1.这里通过for循环列出数据,绑定需要写样式的className:原有className=‘shop-checked’;选中className=is-shop-checked
<span v-for="(itemIn,index)in data" class="shop-checked-parcel" @click="onShopChecked(itemIn.skuId)">
<image :class="['shop-checked',{'is-shop-checked':groupCheckeds.includes(itemIn.skuId)}]" src="/static/images/icon/checked.png" class="shop-checked" />
</span>
2.选中的Id存放处
data() {
return {
groupCheckeds: [],
};
},
3.写在methods中的方法
onShopChecked(skuId) {
let self = this;
let arr = self.groupCheckeds;
let checkedData = []
if(arr.includes(skuId)){
let index = arr.indexOf(skuId);
if(index > -1){
arr.splice(index,1)
}
}else if(self.groupCheckeds.length = 1){
self.groupCheckeds.push(skuId)
}else if(self.groupCheckeds.length > 1){
uni.showToast({
title: '超出批量操作限制',
duration: 1000,
position: "bottom",
icon: "none",
});
return
}
self.groupCheckeds.map((item)=>{
checkedData.push(item)
})
self.$emit('childrenData',checkedData)
}