[Vuejs]-Vue.js – Error : Uncaught ReferenceError: getters is not defined

0👍

You should use store.getters.variable_name to retrieve state value.

Sample code for retrieving accessToken:

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    accessToken: null
  },
  getters: {
    accessToken: state => state.accessToken
  },
  actions: {
    doSomethingsHere({ commit }, somethingData) {
      console.log('accessToken: ' + store.getters.accessToken)
    }
  }
})

export default store

Leave a comment