我有两种不同的语法。我可以使用mapGetters()和mapActions()访问我的getter和我的动作。第一个不解构状态参数并且有效。第二个确实解构了状态,但是当getter可以访问状态时,变异不会改变状态,并且动作解构上下文没有问题。
我不明白为什么。我是否滥用ES6 / vuejs / vuex / quasar?
Vue.use(Vuex)
export default new Vuex.Store({
state: {
counter1: 0,
counter2: 0
},
getters: {
counter1: state => state.counter1,
counter2: ({ counter2 }) => counter2
},
mutations: {
increment1: state => state.counter1++,
increment2: ({ counter2 }) => counter2++
},
actions: {
increment1: context => context.commit('increment1'),
increment2: ({ commit }) => commit('increment2')
}
})
我的一个朋友给了我答案。我误用了ES6。
{counter2}不引用state.counter2,但会复制它。
更改counter2时我无法更改state.counter2。