【问题标题】:Vue.js 2/Vuex - How to call getters from modules that has attribute namespaced:true without mapGetters?Vue.js 2/Vuex - 如何在没有 mapGetters 的情况下从具有 namespaced:true 属性的模块调用 getter?
【发布时间】:2017-11-16 10:35:03
【问题描述】:

这是我的模块:

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

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

【问题讨论】:

    标签: vuejs2 vuex


    【解决方案1】:

    查看How to access Vuex module getters and mutations的第二个答案

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

    【讨论】:

    • 有效!!非常感谢!我之前看过那篇文章,但没想到它会与 params 一起使用。
    猜你喜欢
    • 2021-01-27
    • 1970-01-01
    • 2019-01-09
    • 2018-04-06
    • 2017-06-11
    • 2019-01-02
    • 2023-04-06
    • 2021-03-10
    • 1970-01-01
    相关资源
    最近更新 更多