1. 商品数量增减

2. 用深度监听同步到本地存储
This commit is contained in:
jqtmviyu@gmail.com 2021-03-05 00:17:31 +08:00
parent ce2539f983
commit 96651e2d32

View File

@ -7,9 +7,9 @@
<goodsItem :item="item" /> <goodsItem :item="item" />
<!-- 3. 计数器 --> <!-- 3. 计数器 -->
<view class="count"> <view class="count">
<view class="count_btn iconfont icon-jianshao"></view> <view @tap="itemChangeCount(index, -1)" class="count_btn iconfont icon-jianshao"></view>
<text class="count_text">{{ item.goods_count }}</text> <text class="count_text">{{ item.goods_count }}</text>
<view class="count_btn iconfont icon-zengjia"></view> <view @tap="itemChangeCount(index, 1)" class="count_btn iconfont icon-zengjia"></view>
</view> </view>
</view> </view>
@ -47,8 +47,34 @@ export default {
// //
this.selectAll = this.cartList.every(item=>item.goods_select === true) this.selectAll = this.cartList.every(item=>item.goods_select === true)
},
//
itemChangeCount(index, num){
// 1 , ,
if(this.cartList[index].goods_count === 1 && num === -1){
wx.showModal({
content: '是否删除该商品',
success: (res) => {
if (res.confirm) {
this.cartList.splice(index, 1)
}
}
})
return
}
this.cartList[index].goods_count += num
} }
}, },
//
watch: {
cartList: {
deep: true,
handler(val){
uni.setStorageSync("cartList", val)
}
}
}
} }
</script> </script>