求大神们解决vuex unknown getter 问题
发布于 3 年前 作者 feer 1379 次浏览 来自 问答
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利

vuex碰到以下bug:

[vuex] unknown getter: locationsSummary
vuex.esm.js?2f62:419 [vuex] unknown action type: fetchSummaryReport
vuex.esm.js?2f62:419 [vuex] unknown action type: fetchLocationsReport

求问问题在哪啊。。。谢谢
store/index.js

import Vue from "vue";
import Vuex from "vuex";

import report from "./report.module";

Vue.use(Vuex);

export default new Vuex.Store({
  modules: {
    report,
  }
});

store/mutations.type.js

export const SET_LOADING_STATUS = "setLoadingStatus";
export const SET_SUMMARY_REPORT = "setSummaryReport";
export const SET_LOCATIONS_REPORT = "setLocationReport";

store/actions.type.js

export const SUMMARY_REPORT_FETCH = "fetchSummaryReport";
export const LOCATION_REPORT_FETCH = "fetchLocationReport";
export const LOCATIONS_REPORT_FETCH = "fetchLocationsReport";
export const LOCATION_SALES_REPORT_FETCH = "fetchLocationSalesReport";
export const LOCATION_LABORS_REPORT_FETCH = "fetchLocationLaborsReport";

store/report.module.js

import Vue from "vue";

import {
    ReportService,
} from "@/service/ReportService";

import {
    SUMMARY_REPORT_FETCH,
    LOCATIONS_REPORT_FETCH,
    LOCATION_REPORT_FETCH,
    COMMENT_DESTROY,
    LOCATION_SALES_REPORT_FETCH,
    LOCATION_LABORS_REPORT_FETCH
} from "./actions.type";

import {
    SET_LOADING_STATUS,
    SET_SUMMARY_REPORT,
    SET_LOCATIONS_REPORT
} from "./mutations.type";

const initalState = {
    locationsSummary: {},
    locations: null,
    trends: [],
};

export const state = { ...initalState };

export const actions = {
    async [SUMMARY_REPORT_FETCH](context) {
        console.log('???????????????!!');
        context.commit(SET_LOADING_STATUS, 1);
        const { response } = await ReportService.getSummary();
        context.commit(SET_LOADING_STATUS, -1);
        context.commit(SET_SUMMARY_REPORT, response);
        return response;
    },
    async [LOCATIONS_REPORT_FETCH](context) {
        context.commit(SET_LOADING_STATUS, 1);
        const { response } = ReportService.getLocations();
        context.commit(SET_LOADING_STATUS, -1);
        context.commit(SET_Locations_REPORT, response);
        return response;
    }
};
export const mutations = {
    [SET_LOADING_STATUS](state, status) {
        this.$updateloading(status);
    },
    [SET_SUMMARY_REPORT](state, response) {
        state.trends = response.data.trends;
        state.locations = response.data.locations
    }
};
const getters = {
    trends : (state) => {
        console.log(state);
        return state.trends;
    },
    locations : (state) => {
        return state.locations;
    },
    locationsSummary : (state) => {
        return state.locationsSummary;
    }
};

export default {
    state,
    actions,
    mutations,
    getters
  };

component:

import { mapGetters } from "vuex";

import {
  SUMMARY_REPORT_FETCH,
  LOCATIONS_REPORT_FETCH
} from "@/store/actions.type";

  mounted() {
    Promise.all([
      this.$store.dispatch(SUMMARY_REPORT_FETCH),
      this.$store.dispatch(LOCATIONS_REPORT_FETCH)
    ]);
  },
  computed: {
    ...mapGetters(["trends", "locations", "locationsSummary"])
  },
回到顶部