Igoohd
Igoohd

Reputation: 166

How to call multiple namespaced Modules in Vuex

I don't know how to call, multiple NamespacedHelpers with vuex, i tried this:

import { createNamespacedHelpers } from 'vuex'
const { mapActions, mapMutations } = createNamespacedHelpers(['payments', 'auth'])
methods: {
    ...mapActions(['registerBankData', 'updateBankData', 'getBankData'], ['login']),
    ...mapMutations(['setBankData']),
...
}

Also tried this:

import { createNamespacedHelpers } from 'vuex'
const { mapActions, mapMutations } = createNamespacedHelpers('payments', 'auth')
methods: {
    ...mapActions(['registerBankData', 'updateBankData', 'getBankData', 'login']),
    ...mapMutations(['setBankData']),
...
}

but doesn't work..

Upvotes: 3

Views: 617

Answers (2)

frlzjosh
frlzjosh

Reputation: 462

I believe you can do this

import { createNamespacedHelpers } from 'vuex'
const payments = createNamespacedHelpers('payments')
const auth = createNamespacedHelpers('auth')

methods: {
    ...payments.mapActions(['registerBankData', 'updateBankData', 'getBankData']),
    ...auth.mapActions(['authAction', 'login']),
    ...payments.mapMutations(['setBankData']),
...
}

Upvotes: 3

Gabriel Willemann
Gabriel Willemann

Reputation: 1921

Try something like that:

import { mapMutations, mapActions } from 'vuex';

export default {
  methods: {
    ...mapMutations({
      myMutation: 'myModule/myMutation',
    }),
    ...mapActions({
      myAction: 'myModule/myAction',
    }),
  }
}

Upvotes: 3

Related Questions