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
Add a comment  | 

3 Answers 3

Reset to default 24
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]);
  }
}

The easier way is to use name spaced getters:

computed(){
    ...mapGetters('feeders', ['getFeedersById'])
}

本文标签: javascriptHow to use vuex namespaced getters with argumentsStack Overflow