首页 > 解决方案 > Vuex:从不同模块获取器中的另一个模块访问状态

问题描述

我正在尝试从另一个模块中的 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"

标签: javascriptvue.js

解决方案


在模块中定义时,getterrootState作为第三个参数接收:

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

推荐阅读