Vue.js 2/Vuex - 如何在没有 mapGetter 的情况下从具有属性 namespaced:true 的模块中调用 getter?
Vue.js 2/Vuex - How to call getters from modules that has attribute namespaced:true without mapGetters?
这是我的模块:
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
因为我必须将参数传递给函数。
查看此问题的第二个答案
this.$store.getters['ModuleA/getCategory'](this.index)
这是我的模块:
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
因为我必须将参数传递给函数。
查看此问题的第二个答案
this.$store.getters['ModuleA/getCategory'](this.index)