1. 商品数量增减
2. 用深度监听同步到本地存储
This commit is contained in:
parent
ce2539f983
commit
96651e2d32
@ -7,9 +7,9 @@
|
||||
<goodsItem :item="item" />
|
||||
<!-- 3. 计数器 -->
|
||||
<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>
|
||||
<view class="count_btn iconfont icon-zengjia"></view>
|
||||
<view @tap="itemChangeCount(index, 1)" class="count_btn iconfont icon-zengjia"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -47,8 +47,34 @@ export default {
|
||||
|
||||
// 判断全选
|
||||
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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user