可以使用v-bind:class"{active:item.id===currentIndexNav}",
当表达式item.id===currentIndexNav为true时,设置的active样式才会显示出来。
<view @click="activeNav(item.id)" v-for="(item,index) in navList" :key="index" v-bind:class="{nav_item:true,active:item.id===currentIndexNav}">
{{item.text}}
</view>
.nav_item {
padding: 20rpx 45rpx;
font-size: 35rpx;
display: inline-block;
}
.nav_item.active {
border-bottom: 5rpx solid #de688b;
}