vue-analysis icon indicating copy to clipboard operation
vue-analysis copied to clipboard

Vuex-API-数据获取中示例代码错误

Open yangangzhang opened this issue 4 years ago • 0 comments

大佬您好,看您文章Vuex-API-数据获取中示例代码中,有一处

getters: {
  total (state, getters, localState, localGetters) {
    // 可访问全局 state 和 getters,以及如果是在 modules 下面,可以访问到局部 state 和 局部 getters
    return state.a + state.b
  }
}

这个地方是不是写错了? 根据源码:

 store._wrappedGetters[type] = function wrappedGetter (store) {
    return rawGetter(
      local.state, // local state
      local.getters, // local getters
      store.state, // root state
      store.getters // root getters
    )
  }

代码中total的参数有错误,应该更改为:

getters: {
  total (state, getters, rootState, rootGetters) {
    // 可访问全局 state 和 getters,以及如果是在 modules 下面,可以访问到局部 state 和 局部 getters
    return state.a + state.b
  }
}

yangangzhang avatar May 15 '20 01:05 yangangzhang