html部分(与单选一样)
<div class="cards" v-for="(e, index) in userList" :key="index"> <div class="imges"> <img src="./img/xzh.png" alt="" class="imgselect" v-if="e.isChecked" @click="userClick1(e, index)" /> <img src="./img/xz.png" alt="" class="imgselect" v-else @click="userClick1(e, index)" /> <span>{{e.name}}</span> </div> </div>
js部分
this.userList.map((item) => {
item.isChecked = false
})
this.userList = this.current > 1 ? [...this.userList, ...res.data.records] :
res.data.records
userClick1(row, i) {
if (!this.userList[i].isChecked) {
this.userList[i].isChecked = true // 确定
this.namelist.push({ id: row.id, name: row.name }) // 赋值
} else {
this.userList[i].isChecked = false // 取消
this.namelist.map((item, index) => {
// 判断当前项是否取消
if (item.id == row.id) {
// 如果当前项取消了,就删掉当前项
this.namelist.splice(index, 1)
}
})
}
},
效果图