Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vuejs2

vuex

This is my module:

const ModuleA={
   namespaced:true,
   state:{
      categoryList:[
         {name:'all', isActive:true},
         {name:'negotiation', isActive:false},
      ]
   },
   getters:{
      getCategory:(state)=>(index)=>{
        return state.categoryList[index];
      },
   }
}

Without namespaced:true, I can call getCategory with this.$store.getters.getCategory(this.index).

How to call getCategory with namespaced:true? I can't use mapGetters because I have to pass parameter to the function.

like image 785
Firmansyah Ramadhan Avatar asked Oct 26 '25 05:10

Firmansyah Ramadhan


1 Answers

See 2nd answer to this How to access Vuex module getters and mutations

this.$store.getters['ModuleA/getCategory'](this.index)  
like image 61
Richard Matsen Avatar answered Oct 29 '25 08:10

Richard Matsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!