Reputation: 489
I know how to use mapGetters in a single situation, but not both.
Example, I have firstRootGetter
inside store/index.js
, so I will call ...mapGetters(['firstRootGetter'])
in vue component.
If I have firstModuleGetter
and secondModuleGetter
inside store/modules/post.js
, I will call ...mapGetters('post', ['firstModuleGetter', 'secondModuleGetter'])
My question is, how do I call them in single ...mapGetters
. Is it possible?
Right now I have to write 2 lines to call them separately.
Upvotes: 16
Views: 25633
Reputation: 2948
computed: {
...mapGetters('module1', ['getQuestions', 'getAnswers']),
...mapGetters('module2', ['getGrades'])
},
This is the syntax used:
...mapGetters('some/nested/module', [
'someGetter', // -> this.someGetter
'someOtherGetter', // -> this.someOtherGetter
])
Upvotes: 13
Reputation:
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
.
Upvotes: 44