How to use mapGetters with modules and root's getters at the same time?

Yes it is possible, you must supply the namespace to the mapGetters helper in each line, though:

...mapGetters({
  exampleGetter: 'myModule1/exampleGetter',
  anotherGetter: 'myModule2/anotherGetter',
})

If you're trying to combine them into a single getter, use a root action that reads both module stores and returns a combined object. Then mapActions like you would mapGetters.


computed: {
        ...mapGetters('module1', ['getQuestions', 'getAnswers']),
        ...mapGetters('module2', ['getGrades'])
    },

This is the syntax used:

 ...mapGetters('some/nested/module', [
    'someGetter', // -> this.someGetter
    'someOtherGetter', // -> this.someOtherGetter
  ])

Tags:

Vue.Js

Vuex