// 通过pinia添加到购物车商品
//shops 代表每个商品
const addCart = (shops) => {
if (cartStores.shop.includes(shops)) {
cartStores.addItemToArray(shops);
} else {
const index = cartStores.shop.findIndex((item) => item.id === shops.id)
if (index !== -1 ) {
// 购物车中已有该商品,只增加数量 这里有bug
// 如果添加的数量是1
if(shops.num ==1){
cartStores.shop[index].num++;
}else{
cartStores.shop[index].num += shops.num++
}
} else {
// 购物车中没有该商品,添加到购物车
// cartStores.shop.push({ ...shops});
cartStores.addShop(shops);
}
}
购物车添加商品,解决数量添加一个+1, 添加10个,总数量更新 的bug
最新推荐文章于 2025-11-30 19:11:04 发布
3746

被折叠的 条评论
为什么被折叠?



