<view
//如果currentIndex等于数组的下标,就显示active这个样式,要不就显示active2
:class="currentIndex== index?'active':'active2'"
v-for="(item,index) in tfdList" :key="index"
@click="chooseItem(index)" >
<view>序号</view>
<view>用户名</view>
<view>密码</view>
</view>
js代码
data(){{
return{
tfdList:[]需要循环的数组
currentIndex:0,//列表选中下标,默认为0
}
}
methods:{
// 点击选中,默认选中第一条
chooseItem(index) {
this.currentIndex= index
},
}