How do you access rootState
in getters?
const getters = { getParams: rootState => { return rootState.route.params }, }
The above doesn't work. How is this done?
You can access getters in actions, because actions get context as the first argument. like this: actions: { action1: (context, payload) => { console. log(context. getters.
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) => { //...
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.
If this getter is in a module rootState
is the third arguments.
const getters = { getParams: (state, getters, rootState) => { return rootState.route.params } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With