<template>
<view @click="onSelect(item,index)" v-for="(item,index) in list"> //当选择的等于当前id才显示
<image v-if="selected.indexOf(item) >= 0"></image>
<image v-else></image>
</view>
</template>
<script>
export default{
data(){
return{
selected:[ ]
}
},
methods:{
// 选择事件(可多选)
onSelect(item){
const index = this.selected.indexOf(item)
if (index >= 0) {
this.selected.splice(index, 1)
console.log('已取消',this.selected)
} else {
this.selected.push(item)
console.log('已选择',this.selected)
}
},
}
</script>
标签:index,console,多选,自定义,selected,item,事件,log From: https://www.cnblogs.com/xin-kw/p/17432386.html