Search code examples
vue.jsvuex

Grabbing state value inside another module


I created 2 modules:

  • Auth
  • User

When a user is being logged in, I retreive the firstname and lastname which I store as: state.auth.user.firstname and state.auth.user.lastname.

As I created a view which shows the user data in HTML, I want to retrieve user information through the User module with the following function:

const getters = {
  currentUserAccount(rootState){
    return rootState.auth.user;
  }
};

Unfortunately this does not work. Can someone tell me what I can do best?


Solution

  • rootState is passed via 3rd argument

    const getters = {
      currentUserAccount(state, getters, rootState){
        return rootState.auth.user;
      }
    };