index.js :
import Vue from 'vue'import Vuex from 'vuex'
Vue.use(Vuex)
import state from './state'
import actions from './actions'
import mutations from './mutations'
import modA from './modules/modA.js'
export default new Vuex.Store({
state,
actions,
mutations,
modules: {
modA
}
})
state.js :
const state = {count:1
};
export default state;
mutations.js :
const mutations = {increment(state,param){
state.count += n
}
}
export default mutations;
actions.js :
const actions = {incrementAct({commit},argNum){ //argNum为参数
commit('increment',augNum)
}
}
export default actions;
modA.js :
// A 模块的内容const state = {
//A模块的数据
};
const mutations = {
//A模块的 mutations
};
const actions = {
//A模块的actions
};
export default {
state,
actions,
mutations
};
详细用法参见官网:Vuex 官网
还没有评论,来说两句吧...