javascript - 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"
解决方案
在模块中定义时,getterrootState
作为第三个参数接收:
const getters = {
authorizedAdminLinks: (state, getters, rootState) => _.filter(rootState.globals.adminLinks, link => link.seePrivilege >= rootState.globals.auth.privileges),
}
推荐阅读
- c# - 简化任务 foreach 循环 c#
- javascript - 反应嵌套组件错误的道具功能onClick
- ios - 带乘数的领先约束不起作用
- javascript - 无法使用 jQuery 访问元素
- angular6 - 谁能解释为什么我们需要 ngModel 和 #nameField="ngModel" 都在 angular6 表单的相同输入字段中?
- php - imagecopyresampled 似乎没有执行
- reactjs - 动态形式:TypeError:无法读取未定义的属性“值”
- c# - 使用 HTML 敏捷性获取属性值
- android-ndk - 使用 ndk 创建本机后台应用程序
- python - 使用延迟从powershell循环调用python