Reputation: 3
I have a module named 'tasks' in store which has this getter -
getTaskById: state => id => state.idToTask[id]
seems quite straightforward and basic, idToTask is just an object with ids as keys.
Now in the view (the component that displays the task) - it gets taskId as prop from router, I use mapGetters like this -
methods: {
...mapGetters('tasks', ['getTaskById'])
}
and I have a computed:
task() {
return this.getTaskById(this.taskId)
}
I really don't know what went wrong here but I get error of task being undefined (in the template) for some reason...
And I'll just say ahead that I've tried
this.$store.getters['tasks/getTaskById'](taskId)
but it does not seem to work as well...
Any help?
Upvotes: 0
Views: 96
Reputation: 541
Disregard my comment, mapGetters should go in computed, not methods.
computed: {
...mapGetters('tasks', ['getTaskById'])
}
https://vuex.vuejs.org/guide/getters.html
https://github.com/vuejs/vuex/issues/1136
Upvotes: 1