【发布时间】:2021-11-17 09:26:25
【问题描述】:
我想知道当我想给它一个自定义名称并在我的模板中使用这个自定义名称而不是 getter 名称来访问它时,mapGetters 的语法是什么。
const store = createStore({
modules: {
prods: productsModule,
cart: cartModule
}
});
我的 mapGetters 语法错误: ** ['products'] 是我的 getters 函数名称。
...mapGetters({
prod: 'prods', ['products']
})
如果我这样做,它可以工作,但我想使用 mapGetters 来做到这一点
products() {
return this.$store.getters['prods/products'];
}
在我的模板中:
<product-item
v-for="prod in products"
:key="prod.id"
:id="prod.id"
:title="prod.title"
:image="prod.image"
:description="prod.description"
:price="prod.price"
></product-item>
无法在网上找到正确的语法来执行此操作,如果可能,请告诉我。非常感谢!
【问题讨论】: