Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access root state from module getters in vuex

I have root state which contains auth data from nuxt/auth..

Inside store/modules/messages/ I have also state and getters etc..

Inside getters I need to get auth data from root state but I dont know how..

I tried adding rootState to index.js from module:

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

But this still returns module state..

like image 859
Learner Avatar asked Jul 07 '19 11:07

Learner


1 Answers

In a vuex module, a getter gets 4 arguments, namely local state, local getters, root state and root getters.

// messages/getters.js

export function avatar (state, getters, rootState, rootGetters) {
  return rootState.auth.user.avatar
}
like image 105
Sumurai8 Avatar answered Oct 21 '22 04:10

Sumurai8