传递id, 用findIndex找到index

This commit is contained in:
jqtmviyu@gmail.com 2021-03-04 23:06:52 +08:00
parent e3ce8acfc3
commit 3024e8be90

View File

@ -2,7 +2,7 @@
<view class="cart">
<view class="cart_item" v-for="(item, index) in cartList" :key="item.goods_id">
<!-- 1. 选择按钮 -->
<radio class="cart_item_radio" @tap="itemSelectChangeHandle(index)" :checked="item.goods_select" color="#e03440" />
<radio class="cart_item_radio" @tap="itemSelectChangeHandle(item.goods_id)" :checked="item.goods_select" color="#e03440" />
<!-- 2. 商品组件 -->
<goodsItem :item="item" />
<!-- 3. 计数器 -->
@ -37,9 +37,11 @@ export default {
},
methods: {
//
itemSelectChangeHandle(index){
itemSelectChangeHandle(goods_id){
//
this.cartList[index].goods_select = !this.cartList[index].goods_select
// this.cartList[index].goods_select = !this.cartList[index].goods_select
const index = this.cartList.findIndex(item=>item.goods_id === goods_id)
this.cartList[index].goods_select = !this.cartList[index].goods_select
}
},
}