<view class="tabs">
<text
v-for="(item, index) in subTypes"
:key="item.id"
class="text"
:class="{ active: index === activeIndex }"//动态绑定高亮类:判断下标是否等于当前下标
@tap="activeIndex = index" //通过点击事件切换当前的下标赋给高亮下标
>{{ item.title }}</text
>
</view>
<!-- 推荐列表 -->
<scroll-view
enable-back-to-top
v-for="(item, index) in subTypes"
:key="item.id"
v-show="activeIndex === index" //并展示对应的数据列表,没有点击的tab信息就不展示
scroll-y
class="scroll-view"
@scrolltolower="onScrolltolower"
>
//默认 高亮的下标为第一个
const activeIndex = ref(0)
vue实现点击高亮效果
于 2024-05-15 11:55:14 首次发布