purchase-let/store/cart.js

18 lines
524 B
JavaScript
Raw Permalink Normal View History

2024-04-29 18:14:58 +08:00
// 导入定义仓库的方法
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;