//carts.js
export const userCartsStore = defineStore({
id: "carts",
state: () => {
return {
shop:[], //存商品数组
};
},
actions: {
//添加商品的方法
addShop(shops){
this.shop.push(shops)
},
//添加数组
addItemToArray(shops){
if(!this.shop.includes(shops)){
this.shop.push(shops)
}
},
},
});
//DetailsPageView.vue 详情页
//加入购物车方法 ,shops代表当前商品
const addCard = (shops: Object) => {
if (cartStores.shop.includes(shops)) {
cartStores.addItemToArray(shops);
} else {
cartStores.addShop(shops);
}
console.log("11111", cartStores.shop);
02-09
586