Accessing rootState in Vuex getter

softcode picture softcode · Feb 11, 2017 · Viewed 18.1k times · Source

How do you access rootState in getters?

const getters = {
  getParams: rootState => {
    return rootState.route.params
  },
}

The above doesn't work. How is this done?

Answer

Bill Criswell picture Bill Criswell · Feb 11, 2017

If this getter is in a module rootState is the third arguments.

const getters = {
  getParams: (state, getters, rootState) => {
    return rootState.route.params
  }
}