1.调用vuex中的mutation中的方法
this.$store.commit('setEditUser', this.multipleSelection)
2.取出vuex中state的数据
this.$store.state.editUser
3.代码示例
const store = new Vuex.Store({
state: {
count:0
},
mutations: {
// 加1
INCREMENT(state) {
state.count++;
},
// 减1
DECREMENT(state) {
state.count--
}
},
actions: {
increment(context) {
context.commit("INCREMENT");
},
decrement(context) {
context.commit("DECREMENT");
}
}
})
本文介绍了如何使用Vuex进行状态管理,包括通过mutation更新状态的方法,以及如何在组件中读取状态。还提供了具体的代码示例,展示了如何实现计数器功能。
3万+

被折叠的 条评论
为什么被折叠?



