Search code examples
vue.jsvuejs2vuex

How to retrieve data from a specific getters in vue?


How to retrieve data from a specific getters in vue?

this.$store.getters('client/list'))

TypeError: _this.$store.getters is not a function at eval (Login2.vue?3936:64)


Solution

  • Step 1: Set the getter in the store.

    getters: {
         clientList: state => {
              return state.clientList
         }
    }
    

    Step 2: Call the getter in your component as computed

    computed: {
       clientList () {
              return this.$store.getters.clientList
         }
    }
    

    Check your syntax. The getter you posted won't work because you're missing the module-specific syntax.

    As an example from the following link: this.$store.getters['ModuleA/getCategory'](this.index)

    See more here: Vue.js 2/Vuex - How to call getters from modules that has attribute namespaced:true without mapGetters?