在另一个模块中获取状态值
Grabbing state value inside another module
我创建了 2 个模块:
- 授权
- 用户
当用户登录时,我检索存储为的名字和姓氏:
state.auth.user.firstname 和 state.auth.user.lastname.
因为我创建了一个显示 HTML 中的用户数据的视图,所以我想通过具有以下功能的用户模块检索用户信息:
const getters = {
currentUserAccount(rootState){
return rootState.auth.user;
}
};
不幸的是,这不起作用。谁能告诉我我最擅长什么?
rootState 通过第三个参数传递
const getters = {
currentUserAccount(state, getters, rootState){
return rootState.auth.user;
}
};
我创建了 2 个模块:
- 授权
- 用户
当用户登录时,我检索存储为的名字和姓氏: state.auth.user.firstname 和 state.auth.user.lastname.
因为我创建了一个显示 HTML 中的用户数据的视图,所以我想通过具有以下功能的用户模块检索用户信息:
const getters = {
currentUserAccount(rootState){
return rootState.auth.user;
}
};
不幸的是,这不起作用。谁能告诉我我最擅长什么?
rootState 通过第三个参数传递
const getters = {
currentUserAccount(state, getters, rootState){
return rootState.auth.user;
}
};