vuejs2 - Vue.js 2/Vuex - 如何从具有命名空间属性 :true without mapGetters? 的模块调用 getter

标签 vuejs2 vuex

这是我的模块:

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

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

如何调用getCategorynamespaced:true ?我无法使用 mapGetters因为我必须将参数传递给函数。

最佳答案

请参阅此 How to access Vuex module getters and mutations 的第二个答案

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

关于vuejs2 - Vue.js 2/Vuex - 如何从具有命名空间属性 :true without mapGetters? 的模块调用 getter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327388/

相关文章:

vue.js - 元素用户界面 : font-family differencies between components

html - 在 HTML block 中显示在 v-model 中输入的 URL

javascript - 列表渲染中的 Vuex 和 react 性

javascript - 在 Vue JS 中访问存储值

javascript - 更改 Vuetify v-card 图像的高度?

vue.js - Nuxt/Vue/Bootstrap-vue 在滚动时缩小导航栏

javascript - vue 中的 JsonEditor 组件未显示

vue.js - 如何使用 vue 组件禁用浏览器上的后退按钮?

javascript - 视觉 : How to use Per-Route Guard with Vuex getter?

javascript - 无法从数组 Vuex 中删除项目