我的root状态,其中包含来自nuxt/auth的auth数据。
在商店/模块/消息/我也有状态和Getters等。
内部getters我需要从根状态获取auth数据,但我不知道如何。
我尝试将rootstate从模块中添加到index.js:
import state from './state'
import rootState from '../../state'
import * as actions from './actions'
import * as mutations from './mutations'
import * as getters from './getters'
export default {
namespaced: true,
state,
rootState,
getters,
mutations,
actions
}
export const avatar = (rootState) => rootState.auth.user.avatar
但这仍然返回模块状态..
在vuex模块中,getter获取4个参数,即本地状态,本地getters,root状态和根geters。
// messages/getters.js
export function avatar (state, getters, rootState, rootGetters) {
return rootState.auth.user.avatar
}