[Vuejs]-State.user is null when using Vuex getter

2👍

Mutations accept only two parameters: first – state, second – payload. If you want to pass multiple parameters in payload use an object.

commit('auth_success', { token, user })

The in mutations:

auth_success(state, payload){
      const { token, user } = payload
      state.status = 'success'
      state.token = token
      state.user = user
    },

1👍

Mutations expect two arguments: state and payload, where the current state of the store is passed by Vuex itself as the first argument and the second argument holds any parameters you need to pass.

You need to destructure the auth_success mutations parameters:

auth_success(state, { token, user }){
      state.status = 'success'
      state.token = token
      state.user = user
},

Quote reference: Vuex – passing multiple parameters to mutation

Leave a comment