API 文档 • 文档
函数: mapStores()
mapStores<
Stores
>(...stores
):_Spread
<Stores
>
允许在没有组合式 API (setup()
) 的情况下使用存储,通过生成一个要在组件的 computed
字段中展开的对象。它接受一个存储定义列表。
类型参数
• Stores extends any
[]
参数
• ...stores: [...Stores[]
]
要映射到对象的存储列表
返回值
_Spread
<Stores
>
示例
js
export default {
computed: {
// other computed properties
...mapStores(useUserStore, useCartStore)
},
created() {
this.userStore // store with id "user"
this.cartStore // store with id "cart"
}
}