admin管理员组文章数量:1182267
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?
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?
Share Improve this question edited May 22, 2018 at 6:37 Canor asked Jan 23, 2018 at 11:13 CanorCanor 9191 gold badge9 silver badges26 bronze badges 4- Have you seen this question on the official GitHub page maybe: github.com/vuejs/vuex/issues/688 – vahdet Commented Jan 23, 2018 at 11:26
- Still not working for the edited function – Canor Commented Jan 23, 2018 at 11:47
- Works now :D Thanks! :P – Canor Commented Jan 23, 2018 at 12:31
- So, is the final edit the one working with namespaces? Maybe someone would come along with the same issue and can be able to see where s/he should fix ;) – vahdet Commented Jan 23, 2018 at 12:35
3 Answers
Reset to default 24feedersById(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]);
}
}
The easier way is to use name spaced getters:
computed(){
...mapGetters('feeders', ['getFeedersById'])
}
本文标签: javascriptHow to use vuex namespaced getters with argumentsStack Overflow
版权声明:本文标题:javascript - How to use vuex namespaced getters with arguments? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738211023a2068840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论