直接在
store/modules
目录中新建js
文件为vuex
自定义的模块
本文以kaifamiao.js
文件为例
const kaifamiao = {
state: {
options: {}
},
mutations: {
setOption(state, option){
state.options = option
}
},
actions: {
setOption(context, option) {
context.commit('setOption', option)
}
},
getters: {
// getOption(state) {
// return state.options
// }
option: state => state.options
}
}
export default {
namespaced: true,
...kaifamiao
}
位置:
/store/index.js
在需要的位置
this.store.commit('kaifamiao/setOption', this.option)
console.log(this.store.getters['kaifamiao/option'])
powered by kaifamiao