未捕获的TypeError:无法读取未定义的属性“ getter”

时间:2020-04-23 14:17:12

标签: vue.js vuex getter

在这里,我已经用vue设置了laravel 6项目,并用vuetify创建了一个crud表,但是由于某种原因,我无法将vueX导入到我的vue组件中。

错误:

./ resources / js / store / index.js 8:11-16中的警告“导出'阶段'为 在'./modules/stage.js'@ ./resources/js/app.js @ multi中找不到 ./resources/js/app.js ./resources/sass/app.scss

控制台错误: 未捕获的TypeError:无法读取未定义的属性“ getters”

index.js

(0 to n). map(_ => new A).toVector

stage.js

import Vue from 'vue';
import Vuex from 'vuex';

//import {stage}  from './stage.js';
import {stage} from './modules/stage.js';




Vue.use(Vuex);

export default new Vuex.Store({
  modules: {
   stage
  },
  state: {},
  mutations: {},
  actions: {},
  getters: {}
});

Stage.vue

export default  {
    state: {
      stages: []
    },
    mutations: {
        ADD_STAGE(state, stage) {
            state.stages.push({
                id: this.getters.newStageid,
                code: stage.code,
                name: stage.name,
                description: stage.description

            });
        },
        UPDATE_STAGE(state, payload){
            state.stages = state.stages.map(stage => {
                if (stage.id === payload.id) {
                    return Object.assign({}, stage, payload)
                }
                return stage;
            })
        },
        REMOVE_STAGE(state, stage){
            var stages = state.stages;
            var id = stage.id;
            var index = state.stages.findIndex(stage => stage.id == id)
            stages.splice(index, 1);
        },
    },
    actions: {
        getStage({commit}, stage){
            commit('GET_STAGE', stage)
        },
        addStage({commit}, stage){
            commit('ADD_STAGE', stage)
        },
        updateStage({commit}, payload){
            commit('UPDATE_STAGE', payload)
        },
        removeStage({commit}, stage){
            commit('REMOVE_STAGE', stage)
        },
    },
    getters: {
      stages: state => state.stages,
      newStageid(state) {  return state.stages.length > 0 ? state.stages[state.stages.length-1].id + 1 : 1; },
    }
}

0 个答案:

没有答案