B
B
BonBon Slick2020-02-12 18:29:22
Vue.js
BonBon Slick, 2020-02-12 18:29:22

Vuex mapState is not a function?

https://vuex.vuejs.org/guide/getters.html#method-s...

computed: {
        ...mapState(LISTS, {
            human (state, getters) {
                 return getters[`user_list/${GET_ELEMENT_BY_FILED_NAME_AND_VALUE}`];
// or
                return getters[`user_list/${GET_ELEMENT_BY_FILED_NAME_AND_VALUE}`]('id', 1);
            },
        }),
    },
    mounted () {
        console.log(this.human({id: 1}));
    },


human is not a function
or
client.js?06a0:77 TypeError: getters["".concat(...).concat(...)] is not a function
    at VueComponent.human (index.js?2400:19)
    at VueComponent.mappedState (vuex.esm.js?2f62:854)
    at Watcher.get (vue.runtime.esm.js?2b0e:4479)

The code above is not working, is it correct?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-12
@Kozack Vue.js

So maybe it's worth using mapGetters?
Let's say something like this

...mapGetters({
  human: `user_list/${GET_ELEMENT_BY_FILED_NAME_AND_VALUE}`
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question