kamila
kamila

Reputation: 55

Vuex module namespace not found in mapActions()

I'm getting the following error while trying to call an action from my store:

[vuex] module namespace not found in mapActions(): feedbacksessionStore/

From other solutions that I found online people were suggesting to set 'namespaced: true', however it doesn't help for my case somehow.

Here is the snippet of my store code:

export const feedbackSessionStore = {
    namespaced: true,

    state: {
        feedback_sessions: {},
    },

    actions: {

        async createFeedbackSession({commit, state}, { data }) {
          // some code
        }
    }
}

And the snippet of the component code:


import { mapGetters, mapState, mapActions } from 'vuex'

// some code

export default {
  name: 'create-edit-feedback-session',
  methods: {
    ...mapActions('feedbackSessionStore', [
        'createFeedbackSession'
    ]),
    // some code
}

Upvotes: 4

Views: 10942

Answers (2)

Can Tomris
Can Tomris

Reputation: 31

In addition to El-Hani's answer, inside your store folder there must be an index.js file which contains your store modules. In that file import the module and register it.

// store/index.js
import 'feedbackSessionStore' from './modules/feedbackSessionStore.js'
    
Vue.use(Vuex)
    
export default new Vuex.Store({
    modules: {
        feedbackSessionStore // <- Register here, and mapAction name becomes this
    }
}

And check if the pointed mapAction name is exactly the same with here.

Upvotes: 0

El-Hani
El-Hani

Reputation: 183

As a solution to this problem you have to do tow things:

  1. make a 'feedbackSessionStore.js' as a separate module by doing this code in store/modules directory:

    namespaced: true,
    
    state: {
        feedback_sessions: {},
    },
    
    actions: {
    
        async createFeedbackSession({commit, state}, { data }) {
          // some code
        }
    }
    
  2. add this module to the store/index.js like that:

    import * as feedbackSessionStore from "@/store/modules/feedbackSessionStore.js";
    

after these two steps it should work.

Upvotes: 7

Related Questions