效果图:
template:
<view :class="{'cur': rSelect.indexOf(index)!=-1}" v-for="(value,index) in infoArr" :key="index" @tap="tapInfo(index)">{{value.name}}</view>
js:
export default {
data(){
return{
rSelect:[]
}
},
methods:{
tapInfo(e) {
if (this.rSelect.indexOf(e) == -1) {
console.log(e)//打印下标
this.rSelect.push(e);//选中添加到数组里
} else {
this.rSelect.splice(this.rSelect.indexOf(e), 1); //取消
}
}
}
}
css(选中样式):
.cur {
color: white;
border: 1px solid #e5e5e5;
background-color: #ff5d00;
}