购物车添加商品

This commit is contained in:
jqtmviyu@gmail.com 2021-02-27 19:38:00 +08:00
parent ea34fe93f5
commit c6b6e21ca0

View File

@ -125,7 +125,28 @@ export default {
//
addToCartHandle(){
console.log('加入购物车')
const cartList = uni.getStorageSync("cartList") || [];
const index = cartList.findIndex((item) => item.goods_id === this.goods_id)
if (index === -1) {
const goodsObj = {
goods_id: this.goods_id,
goods_small_logo: this.goods_small_logo,
goods_price: this.goods_price,
goods_name: this.goods_name,
goods_select: true, //
goods_count: 1, //
}
cartList.push(goodsObj)
}else{
cartList[index].goods_count += 1
}
uni.setStorageSync("cartList", cartList)
uni.showToast({
title: "加入成功",
// 穿
mask: true,
duration: 1000,
})
}
},