export default new Vuex.Store({
state: {
cart_list:[1,2,3],
},
getters: {
total: state => {
var total = state.cart_list[0]+state.cart_list[1]+state.cart_list[2];
return total;
}
},
mutations: {
get_total (state) {
console.log(">>>>>我的问题是:这里如何调用到 getters>total ?");
}
}
})
我现在的实现方法是,在调用的组件中用了一个:
this.$store.commit('get_total',this.$store.getters.total);
把total传入,这样做是对的么?
getter
相当于state
的计算属性,mutation
是用来修改state
的。mutation 直接修改 getter 不是正确操作啊。