Skip to content
Fix Code Error

Nuxt.js Store, dispatch action to other store

April 7, 2021 by Code Error
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

Related Articles

  • How to dispatch a Redux action with a timeout?
  • Nuxt + Vuex - How do I break down a Vuex module into…
  • Axios Interceptors retry original request and access…
  • How to avoid the need of writing…
  • vuex - is it possible to directly change state, even…
  • How do I set initial state in Vuex 2?
  • Access-Control-Allow-Origin: * in tomcat
  • Jetty: HTTP ERROR: 503/ Service Unavailable
  • how to update child component's property using props…
  • How to test mutations when using vuex modules
  • Axios interceptor in vue 2 JS using vuex
  • Vue.prototype is undefined on first load of the page
  • vuex- state returned as function or object literal
  • How to use html template with vue.js
  • Nuxt Hot reloading for new components Is not working
  • Vue.js vuex state not working correctly
  • Is there a created() for vuex actions to auto dispatch
  • Vuex Modules issue with _mapGetters() : getters…
  • Auto SignIn with Vuex and Vuex-persistedstate
  • VueJS - VueX and flash messages
  • How to use `$axios` in utility function in Vuex of Nuxt.js
  • Cannot dispatch namespaced action from a separate…
  • Can't install via pip because of egg_info error
  • Why do we need middleware for async flow in Redux?
  • Why does my instance of Axios not return the…
  • Name spacing not working in vuex maps throwing…
  • Calling a component function from the store once an…
  • Vuex Classic mode for store/ is deprecated and will…
  • Mutate vuex store state with action within axios…
  • how to get data from API in vuex using axios?
  • Could not resolve placeholder in string value
  • Reference - What does this regex mean?
  • How to properly use Vuex module mode for Nuxt JS?
  • Why does writeObject throw…
  • Vuex - Run function after multiple dispatches
  • What is a NullReferenceException, and how do I fix it?
  • The ResourceConfig instance does not contain any…
  • Spring CORS No 'Access-Control-Allow-Origin' header…
  • VueJS role based authentication with router
  • Issues with registering Vuex modules, either…
  • Vue checking if action calls other action with spyOn
  • Programmatically select a row in JTable
  • Is it possible to use Vuex without Vue? (Vuex server-side?)
  • Passing event and argument to v-on in Vue.js
  • What is the right way to make API calls with Vuex?
  • Java web start - Unable to load resource
  • Property or method not defined on the instance but…
  • error LNK2005: xxx already defined in…
  • CSS Float: Floating an image to the left of the text
  • Making axios global in Vue project is not working
  • Difference between variable declaration syntaxes in…
  • How to remove MySQL completely with config and…
  • Mocking Vuex module action in component unit test
  • Structuring a Vue + Vuex project
  • Nuxt js how dispatch action in store and change state
  • Nuxt.js error: The client-side rendered virtual DOM…
  • Better approach handling: 'Do not mutate vuex store…
  • Axios catch error Request failed with status code 404
  • coercing to Unicode: need string or buffer, NoneType…
  • render function or template not defined in…
  • Retrieve specific commit from a remote Git repository
  • Vue: disable no-unused-vars error: the simplest fix
  • Attach Authorization header for all axios requests
  • Updating an item in an array updates them all
  • Access Vuex before Vue route is resolved
  • Vuex accessing state BEFORE async action is complete
  • init-param and context-param
  • Refreshing authentication tokens for a Vue.js SPA…
  • Passing vuex module state into vue-router during beforeEach
  • How to use Vuex types constants with module namespace?
  • An Authentication object was not found in the…
  • org.glassfish.jersey.servlet.ServletContainer…
  • Angular: Can't find Promise, Map, Set and Iterator
  • Access module from Vuex Store
  • Receive WebSockets data from vuex and…
  • vuex: unknown getter: user
  • NuxtServerInit not working on Vuex module mode - Nuxt.js
  • How can I display a modal dialog in Redux that…
  • Vuex rendering data that is fetched from REST API
  • Changing a vuex state from a different component?
  • Can a Vuex module watch another Vuex module?
  • Remove value from localStorage in Vuejs
  • How to implement auto refresh in client side(vue.js)?
  • Lists and Components not updating after data change…
  • Accessing Vuex state when defining Vue-Router routes
  • Content is not allowed in Prolog SAXParserException
  • Pros/cons of using redux-saga with ES6 generators vs…
  • Vue&TypeScript: how to avoid error TS2345 when…
  • Initializing VueX Store Not Working
  • git pull while not in a git directory
  • Is it possible to dispatch an action inside Vuex…
  • How do I make a Git commit in the past?
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Can I call commit from one of mutations in Vuex store
  • Throw HttpResponseException or return…
  • Saving data to a file in C#
  • How to get vuex state from a javascript file…
  • Vuex: [vuex] module namespace not found in…
  • How to use Servlets and Ajax?
  • Vuex mapstate object undefined and "[vuex] unknown…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to get type backbone model?

Next Post:

Vuejs and Page Refresh on click

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Vue 3 Composition API Provide/Inject not working in Single File Components
  • Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead
  • How to pass a model to a template rendered from a route in Ember 1.6
  • Backbonejs – Avoid parse after save
  • BackboneJS: View renders fine, but refreshes with undefined collection
  • Explicit call vuex actions in the `.vue` component detach/ready function
  • jest.fn() claims not to have been called, but has
  • I18Next doesn’t work when loading data from backend
  • Properly setting the context for an Ember partial rendered from within a template
  • Custom Backbone Sync
  • Vue-router page refresh or URL access
  • Vue.js – Unknown custom element:
  • server returning 302 moved on create in Rails
  • TypeError: Cannot call method ‘replace’ of null – Backbone.js
  • Capture div containing inline svg and download it as image
  • Overview of the Ember.js code
  • Polymer 1.0 – HIDE Paper Drawer Panel
  • How to get a backend error message on the frontend using Fetch
  • How to change day-format (M > Mo, F > Fr…) in Date/month pickers of Vuetify
  • Vue.js cache method outcome?

Categories Tags

.net (1074) ajax (457) android (2318) angularjs (553) arrays (1090) asp.net (630) backbone.js (2262) bash (760) c++ (4925) css (2466) date (485) datetime (471) ember.js (1279) excel (566) git (1084) html (3345) ios (701) java (4508) javascript (9390) jquery (2998) json (943) laravel (507) linux (797) list (561) mysql (1310) node.js (895) oracle (475) pandas (449) php (2230) python (4372) r (537) reactjs (545) regex (554) shell (517) sql (1847) sql-server (1217) string (1360) tsql (471) twitter-bootstrap (515) typescript (418) vue-component (716) vue.js (5164) vuejs2 (1675) vuetify.js (495) windows (590)
© 2021 Fix Code Error