How to access the getter from another Vuex module?

Sometimes, we want to access the getter from another Vuex module.

In this article, we’ll look at how to access the getter from another Vuex module.

How to access the getter from another Vuex module?

To access the getter from another Vuex module, we can get them from the rootGetters parameter.

For instance, we write

const store = new Vuex.Store({
  //...
  getters: {
    someGetter: (state, getters, rootState, rootGetters) => {
      //...
      rootGetters.someOtherGetter;
      rootGetters["bar/someOtherGetter"];
      //...
    },
    //...
  },
  //...
});

to create a Vuex.Store instance with the someGetter getter.

In it, we get the someOtherGetter getter with rootGetters.someOtherGetter.

And we get the namespaced bar/someOtherGetter getter with rootGetters["bar/someOtherGetter"].

Conclusion

To access the getter from another Vuex module, we can get them from the rootGetters parameter.