Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing rootState in Vuex getter

How do you access rootState in getters?

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

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

like image 873
softcode Avatar asked Feb 11 '17 01:02

softcode


People also ask

How do you access getters in mutations Vuex?

You can access getters in actions, because actions get context as the first argument. like this: actions: { action1: (context, payload) => { console. log(context. getters.

How do I get getter from another Vuex module?

To access the getter from another Vuex module, we can get them from the rootGetters parameter. const store = new Vuex. Store({ //... getters: { someGetter: (state, getters, rootState, rootGetters) => { //...

How do I access the Vue getters?

In any case you can call console. log(this. $store) to debug the Store. If you do so you will see the getters are prefixed with the namespace in their name.


1 Answers

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

const getters = {   getParams: (state, getters, rootState) => {     return rootState.route.params   } } 
like image 152
Bill Criswell Avatar answered Sep 26 '22 03:09

Bill Criswell