今天早些时候尝试vuex 2.1.2 vue:2.1.0,目录结构如下
store.js:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import common from './common/store'
export default new Vuex.Store({
modules : {
common
}
})
mutation-types.js:
export const ADD_NUM = "ADD_NUM"
公共/ store.js:
import * as types from '../mutations-types'
const state = {
num : 1
}
const mutations = {
[types.ADD_NUM] : function(state){
state.num = state.num + 1;
},
}
export default {
state,
mutations
}
公共/ actions.js:
import * as types from '../mutations-types'
export default {
setNum : store => {
store.dispatch(types.ADD_NUM)
},
}
公共/ getters.js:
export default {
getNum : state => {
state.common.num
},
}
然后通过getter
获取Hello.vue中num的值
在vue条目文件main.js中,注入商店
运行错误:
属性或方法“getNum”未在实例上定义,但是 在渲染期间引用
为什么会报告此错误?这个目录结构和代码是否正确?