【问题标题】:Vuex getter destructVuex getter 破坏
【发布时间】:2019-11-03 07:38:46
【问题描述】:

我正在使用 Vue.js 和 Vuex,想知道有没有办法像 actions 那样破坏 getter

这个吸气剂:

  doneTodosCount: (state, getters, rootState, rootGetters) => {
      .....
  }

变成这样:

  doneTodosCount: ({rootGetters}) => {
          .....
  }

问这个,因为在第一个例子中,我不需要前三个参数 state, getters, rootState 但仍然需要编写它们以达到第四个 rootGetters

【问题讨论】:

    标签: vue.js vuex store


    【解决方案1】:

    你不能,因为你没有解构任何对象;您需要以正确的顺序列出参数。

    我想你可以编写一个忽略前 3 个参数的辅助函数,但老实说,我认为它没有那么有用。

    const f = fn => (state, getters, rootState, rootGetters) => fn(rootGetters)
    
    export default {
      doneTodosCount: f(rootGetters => {
        ...
      })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 2021-05-04
      • 2017-04-13
      • 2020-10-05
      • 2019-10-19
      • 1970-01-01
      • 2019-08-21
      相关资源
      最近更新 更多