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

别说谁变了你拦得住时间么 提交于 2020-01-04 02:11:48

问题


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.


回答1:


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

this.$store.getters['ModuleA/getCategory'](this.index)  


来源:https://stackoverflow.com/questions/47327388/vue-js-2-vuex-how-to-call-getters-from-modules-that-has-attribute-namespacedt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!