gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:18:25 24 4
gpt4 key购买 nike

这是我的模块:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com