tab分页高亮切换及tab交互

当用户点击页面中的 Tab 后,切换展示相应的商品列表,功能相对简单,快速实现即可。

// 存储高亮的下标
<script setup lang="ts">
// 高亮的下标
const activeIndex = ref(0)
</script>

<template>
  <!-- 推荐选项 -->
  <view class="tabs">
    <text
      class="text"
      v-for="(item, index) in subTypes"
      :key="item.id"
      :class="{ active: index === activeIndex }"
      @tap="activeIndex = index"
    >
      {
   {
    item.title }}
    </text>
  </view>
  <!-- 推荐列表 -->
  //  v-show="activeIndex === index"  点击tab切换可以切换数据,tab的交互
  <scroll-view
    scroll-y
    class="scroll-view"
    v-for="(item, index) in subTypes"
    :key="item.id"
    v-show="activeIndex === index"
  >
    ...省略
  </scroll-view>
</template>

<style>
.tabs {
   
  display: flex;
  justify-content: space-evenly;
  height: 100rpx;
  line-height: 90rpx;
  margin: 0 20rpx;
  font-size: 28rpx;
  border-radius: 10rpx;
  box-shadow: 0 4rpx 5rpx rgba(200, 200, 200, 0.3);
  color: #333;
  background-color: #fff;
  position: relative;
  z-index: 9;
  .text {
   
    margin: 0 20rpx;
    position: relative;
  }
  .active {
   
    &::after {
   
      content: '';
      width: 40rpx;
      height: 4rpx;
      transform: translate(-50%);
      background-color: #27ba9b;
      position: absolute;
      left: 50%;
      bottom: 24rpx;
    }
  }
}
</style>

相关推荐

  1. tab切换tab交互

    2024-01-10 07:22:05       39 阅读
  2. quasar框架切换Tab使用<keep-alive>缓存

    2024-01-10 07:22:05       12 阅读
  3. tab切换 vue

    2024-01-10 07:22:05       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-10 07:22:05       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-10 07:22:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-10 07:22:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-10 07:22:05       18 阅读

热门阅读

  1. 面试 React 框架八股文十问十答第三期

    2024-01-10 07:22:05       39 阅读
  2. easyExcel 获取多个sheet中复杂表头的数据

    2024-01-10 07:22:05       41 阅读
  3. EasyExcel快速导出 100W 数据

    2024-01-10 07:22:05       34 阅读
  4. 【React源码 - Fiber架构之Renderer】

    2024-01-10 07:22:05       40 阅读