Nuxt.js Store, dispatch action to other store
Posted By: user9801251
I have two stores on my Nuxt.js app and I need to dispatch an action to another store.
export const actions = {
addToCart({ state, commit, dispatch }) {
dispatch('CartLoadingStore/enableLoadingBar')
this.$axios
.post('something')
.then(response => {
(...)
dispatch('CartLoadingStore/disableLoadingBar')
})
},
}
It seems to me like I cannot dispatch an action to a different store. Is that right? Or is there a way to do so?
The above will result in the error:
[vuex] unknown local action type: CartLoadingStore/enableLoadingBar, global type: StoreTheActionDispatchedFrom/CartLoadingStore/enableLoadingBar
Solution
You need to add root param to your dispatch call
dispatch('CartLoadingStore/disableLoadingBar', null, { root: true })
Here docs
Answered By: Anonymous
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.