Vuex变异:使用ES6语法解析状态参数(使用类星体框架)

问题描述 投票:0回答:1

我有两种不同的语法。我可以使用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')
  }
})
ecmascript-6 vuejs2 vuex quasar-framework
1个回答
0
投票

我的一个朋友给了我答案。我误用了ES6。

{counter2}不引用state.counter2,但会复制它。

更改counter2时我无法更改state.counter2。

© www.soinside.com 2019 - 2024. All rights reserved.