传递id, 用findIndex找到index
This commit is contained in:
parent
e3ce8acfc3
commit
3024e8be90
@ -2,7 +2,7 @@
|
|||||||
<view class="cart">
|
<view class="cart">
|
||||||
<view class="cart_item" v-for="(item, index) in cartList" :key="item.goods_id">
|
<view class="cart_item" v-for="(item, index) in cartList" :key="item.goods_id">
|
||||||
<!-- 1. 选择按钮 -->
|
<!-- 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. 商品组件 -->
|
<!-- 2. 商品组件 -->
|
||||||
<goodsItem :item="item" />
|
<goodsItem :item="item" />
|
||||||
<!-- 3. 计数器 -->
|
<!-- 3. 计数器 -->
|
||||||
@ -37,8 +37,10 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 商品选择按钮切换
|
// 商品选择按钮切换
|
||||||
itemSelectChangeHandle(index){
|
itemSelectChangeHandle(goods_id){
|
||||||
// 选中状态取反
|
// 选中状态取反
|
||||||
|
// 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
|
this.cartList[index].goods_select = !this.cartList[index].goods_select
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user