循环显示标签的代码:
<view
v-for="(item,index) in tabBars" :key="item.id"
class="nav-item"
:class="{current: index === tabCurrentIndex}"
:id="'tab'+index"
@click="changeTab(index)"
>{{item.name}}</view>
选中标签页的样式:
.current{
color: #007aff;
}
切换标签页方法:
changeTab(e){
let index = e;
this.tabCurrentIndex = index;
}
本文介绍了一种使用v-for指令在前端循环显示标签的方法,包括如何为当前选中的标签添加样式,以及通过点击事件切换不同标签页的实现细节。
279

被折叠的 条评论
为什么被折叠?



