Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting unknown local action type in Vuex Store

Tags:

vue.js

vuex

I have broken up my Vuex store into namespaced modules.

I have created a User module, where I need to call my Showrooms module. The interesting thing, is that this action works fine. But I am updating the store:

dispatch('showrooms/updateLocalShowroom',
  {
    weddingId: element.wedding.id,
    showroomDresses: element.showroom.showroomDresses,
    status: element.showroom.status,
    uuid: element.showroom.uuid,
  }, 
    { 
      root: true 
    }
 )

But when I try and reset the Showrooms store with this: dispatch('showrooms/resetShowrooms', { root: true })

I get the following error:

[vuex] unknown local action type: showrooms/resetShowrooms, global type: user/showrooms/resetShowrooms

The only thing I can think of is something is that when I resetShowrooms I do it like this in my store module:

This action:

resetShowrooms: ({ commit }) => {
  commit('zeroOutShowrooms')
},

Calls this mutation

zeroOutShowrooms: (state) => {
  Vue.set(state, 'showrooms', [])
}
like image 243
ToddT Avatar asked Oct 13 '20 19:10

ToddT


1 Answers

It ends up that dispatch is looking for some data in the second position. That's why this was NOT working:

resetShowrooms: ({ commit }) => {
  commit('zeroOutShowrooms')
},

While this DID work and solved my issue:

dispatch('showrooms/resetShowrooms', '', { root: true })

Just sending the empty string did the trick and all is good now.

like image 60
ToddT Avatar answered Oct 16 '22 12:10

ToddT