18 lines
524 B
JavaScript
18 lines
524 B
JavaScript
// 导入定义仓库的方法
|
|
import { defineStore } from 'pinia';
|
|
// 导入响应式和计算
|
|
import { ref } from 'vue';
|
|
|
|
// ##### 由于购物车数量可能很多, 路由跳转时无法携带大量参数, 故使用状态管理保存
|
|
const useCartStore = defineStore("cart", () => {
|
|
|
|
const cartList = ref(uni.getStorageSync('cart_id') || []);
|
|
const setCartList = (data)=>{
|
|
cartList.value = data;
|
|
uni.setStorageSync('cart_id', data);
|
|
}
|
|
|
|
return { cartList, setCartList }
|
|
})
|
|
|
|
export default useCartStore; |