VUEX的函数代码:
let mutations = {
changeChooseModule (state, module) {
state.chooseModule[module.id] = module //增加
},
delChooseModule (state, id) {
state.chooseModule.map((v, i) => {
if (v.id === id) {
state.chooseModule.splice(i, 1) //删除
}
})
},
delChooseModuleAll (state, moduleNull) {
state.chooseModule = moduleNull // 清空
}
}
通过commit触发 改变
this.$store.commit('changeChooseModule', this.moduleLists[i])
this.$store.commit('delChooseModule', i)
this.$store.commit('delChooseModuleAll', [])
本文详细介绍了使用Vuex进行模块状态管理的方法,包括增加、删除和清空模块状态的具体实现。通过实例展示了如何利用commit触发状态改变,适用于前端开发中状态管理的需求。
950





