上次的那个版本有点复杂,这次进行优化一下
template源码
<view class="typeButton">
<view class="btn" v-for="(text,index) in but" :key="index" :class="
{isActive:index===s1}" @click="setmun(index)">
{{text.name}}
</view>
</view>
script源码
export default {
data (){
return{
s1:0,
but:[
{name:'城市案件'},{name:'交通案件'},{name:'综合执法'},{name:'水务案件'},
{name:'其他'}
]
}
},
methods:{
setmun(index){
this.s1=index;
}
}
}