Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gabrielbuzzi's avatar

Vuex: Actions with same name in different modules.

I have a module names users and another roles, both modules in my Vuex have the action name setFilter, when i call this actions in my component everytime try to run the users module action. So, how can i say to my component that i want to run the roles module action.

This is how i'm calling the actions in my component.

export default () {
    methods: {
        ...mapActions(['setFilter']),

        changeFilter () {
            // Do shomething
            this.setFilter()
        }
    }
}
0 likes
5 replies
erikgall's avatar

@gabrielbuzzi Check out the namespacing section on the modules page of the vuex docs.

http://vuex.vuejs.org/en/modules.html#namespacing

I just dealt with this issue while my company rebuilds our current Rails application. I found namespacing each action, getter and mutation method to be the best solution. Let me know if you would like a real-world example... Our new platform is a full SPA using vue, vue-router, vuex, vuex-router-sync with a Laravel API backend.

2 likes
gabrielbuzzi's avatar

@erikgall Yeah, i have already read this article, but i have the same problem of @cashlion. The article teach you how to create the namespacing, but don't show you how to get the actions and getter using mapGetters and mapActions.

gabrielbuzzi's avatar

@cashlion this two tutorials is great, but i'm not sure i agree the way the namespacing is done in the example.

Please or to participate in this conversation.