I have issue when Im using vuex.
I have getters in namespaced module and I cant figurę out how to get the data with Ii when Im passing some arguments.
this.$store.getters.feeders.getFeedersById(id)
And in maper.
...mapGetters({
feeders: ['feeders/getFeedersById'](this.id)
Getting error like this getter is not a function. What else shoudl I do?
In the previous Vuex tutorial, we learned that by default, getters, actions, and mutations inside modules are registered under the global namespace, which allows multiple modules to react to the same mutation or action.
Vuex allows us to define "getters" in the store. You can think of them as computed properties for stores. As of Vue 3.0, the getter's result is not cached as the computed property does.
feedersById(state) {
return rowId => {
if (state.feedersArray.hasOwnProperty(rowId)) {
return state.feedersArray[rowId].map(id => state.feeders[id]);
}
}
},
feedersId() {
if (this.rowData) {
return this.$store.getters['feeders/feedersById'](this.rowData.ac_id);
}
}
Okey I had some mistake there and now it works properly. Thanks!! :)
You can also declare a getter function like this:
feedersById: (state) => rowID => {
if (state.feedersArray.hasOwnProperty(rowId)) {
return state.feedersArray[rowId].map(id => state.feeders[id]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With