单选
<!-- 单选 -->
<view class="company-item" :class="{'active': isChange == index}" v-for="(item, index) in list" :key="index" @click="clickBtn(index)">
{{item}}
</view>
isChange:'-1',
list: [],
clickBtn(index){
if(index!=this.isChange){
this.isChange = index;
}else{
}
},
多选
<!-- 多选 -->
<view class="skill-item" :class="{'active': isChange.indexOf(index)!=-1}" v-for="(item, index) in list" :key="index" @click="clickBtn(index)">
{{item}}
</view>
isChange:[],
list: [],
clickBtn(index){
if (this.isChange.indexOf(index) == -1) {
if(this.isChange.length == 3){
uni.showToast({
title:'最多选择三项',
icon:'none'
})
}else{
this.isChange.push(index);
}
} else {
this.isChange.splice(this.isChange.indexOf(index), 1);
}
let list2 = []
for(let index in this.isChange){
list2.push(this.list[this.isChange[index]])
}
},
样式
.company-item{
width:200rpx;
height:50rpx;
border:2rpx solid #555;
border-radius:10rpx;
font-size:30rpx;
color:#555;
text-align: center;
line-height: 50rpx;
}
.active{
border:2rpx solid #DD524D;
color: #DD524D;
}