【问题标题】:Vuex: Accessing state from anther module inside different module getterVuex:从不同模块获取器中的另一个模块访问状态
【发布时间】:2019-07-31 20:44:24
【问题描述】:

我正在尝试从另一个模块中的 getter 中的另一个命名空间 vuex 模块访问状态,这就是我正在尝试的:

//GETTERS
const getters = {

    authorizedAdminLinks: ({ rootState }) =>  _.filter(rootState.globals.adminLinks, link => link.seePrivilege >= rootState.globals.auth.privileges),
}

我收到以下错误:

[Vue warn]: Error in render: "TypeError: rootState is undefined"

【问题讨论】:

    标签: javascript vue.js


    【解决方案1】:

    当在模块中定义时,getter 以a third argument 接收rootState

    const getters = {
        authorizedAdminLinks: (state, getters, rootState) =>  _.filter(rootState.globals.adminLinks, link => link.seePrivilege >= rootState.globals.auth.privileges),
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-12
      • 2018-05-02
      • 2017-07-25
      • 1970-01-01
      • 2019-11-17
      • 2018-02-10
      • 2021-11-07
      • 2021-05-15
      • 2021-08-27
      相关资源
      最近更新 更多