【问题标题】:Vuex mutation: deconstruct state parameter using ES6 syntax (using quasar framework)Vuex 突变:使用 ES6 语法解构状态参数(使用 quasar 框架)
【发布时间】:2019-02-11 15:10:11
【问题描述】:

我有两种不同的语法。我可以使用 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】:

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

{ counter2 } 不引用 state.counter2,而是复制它。

更改 counter2 时无法更改 state.counter2 是有道理的。

【讨论】:

    猜你喜欢
    • 2021-09-16
    • 2021-05-26
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2022-07-14
    • 1970-01-01
    相关资源
    最近更新 更多