Vue.js 2/Vuex - 如何在没有 mapGetters 的情况下从具有属性 namespaced:true 的模块调用 getter? [英] Vue.js 2/Vuex - How to call getters from modules that has attribute namespaced:true without mapGetters?

查看:38
本文介绍了Vue.js 2/Vuex - 如何在没有 mapGetters 的情况下从具有属性 namespaced:true 的模块调用 getter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的模块:

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

如果没有 namespaced:true,我可以用 this.$store.getters.getCategory(this.index) 调用 getCategory.

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

如何使用 namespaced:true 调用 getCategory?我不能使用 mapGetters 因为我必须将参数传递给函数.

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

推荐答案

见第二个回答 如何访问Vuex 模块的getter 和mutations

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

这篇关于Vue.js 2/Vuex - 如何在没有 mapGetters 的情况下从具有属性 namespaced:true 的模块调用 getter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆