Vuex module namespace not found in mapActions()

Viewed 6627

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
}
1 Answers

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.

Related