乐于分享
好东西不私藏

谁用谁高级!uni-app 5 款 Tab 栏

谁用谁高级!uni-app 5 款 Tab 栏

原创声明:本文为雪天前端原创技术文章,未经授权禁止转载、搬运

考虑到兼容性,源码使用的是vue2语法,没有任何依赖库,没有使用CSS 预处理器。直接一键复制就可以了。

01
生活百科 Tab(带搜索 + 更多图标)

标准顶部 Tab,左侧文字切换,右侧带搜索图标 + 更多图标,渐变柔和背景,适合资讯、首页等通用场景。

 

完整源码

<template><viewclass="page-wrapper"><viewclass="tab-container tab-container-1"><viewclass="tab-list"><viewv-for="(item, index) in tabList":key="index"class="tab-item":class="{ active: currentIndex === index }" @click="switchTab(index)">          {{ item.name }}</view></view><viewclass="tab-right"><viewclass="icon-item"><imageclass="icon-img"src="/static/xt-tabs/searchIcon.png"></image></view><viewclass="icon-item"><imageclass="icon-img"src="/static/xt-tabs/more.png"></image></view></view></view><viewclass="content-container"><viewv-show="currentIndex === 0">生活百科内容</view><viewv-show="currentIndex === 1">健康养生内容</view><viewv-show="currentIndex === 2">家居装饰内容</view></view></view></template><script>exportdefault {    data() {return {tabList: [{name'生活百科'          },          {name'健康养生'          },          {name'家居装饰'          }        ],currentIndex0      }    },methods: {      switchTab(index) {this.currentIndex = index      }    }  }</script><stylescoped>.page-wrapper {width100%;min-height100vh;padding20rpx;box-sizing: border-box;  }.tab-container {display: flex;align-items: center;justify-content: space-between;padding020rpx;height88rpx;border-radius44rpx;margin-bottom20rpx;backgroundlinear-gradient(to right, #f5dfe8#dfeff9);  }.tab-list {display: flex;align-items: center;flex1;overflow-x: auto;white-space: nowrap;  }.tab-item {font-size32rpx;font-weight500;color#999;padding020rpx;line-height88rpx;position: relative;transition: all 0.3s ease;flex-shrink0;  }.tab-item.active {font-weight: bold;color#000;  }.tab-right {display: flex;align-items: center;gap10rpx;flex-shrink0;  }.icon-item {width60rpx;height60rpx;display: flex;align-items: center;justify-content: center;  }.icon-img {width40rpx;height40rpx;object-fit: contain;  }.content-container {padding30rpx;font-size28rpx;color#333;  }</style>

原创声明:本文为雪天前端原创技术文章,未经授权禁止转载、搬运

02
常规 Tab(灰色底 + 红色指示器)

浅灰色清爽背景,右侧仅保留搜索图标,选中项底部红色小横条,简洁高级,适合内容分类、社区页面。

完整源码

<template><viewclass="page-wrapper"><viewclass="tab-container tab-container-2"><viewclass="tab-list"><viewv-for="(item, index) in tabList":key="index"class="tab-item":class="{ active: currentIndex === index }" @click="switchTab(index)">          {{ item.name }}</view></view><viewclass="tab-right"><viewclass="icon-item"><imageclass="icon-img"src="/static/xt-tabs/searchIcon.png"></image></view></view></view><viewclass="content-container"><viewv-show="currentIndex === 0">国内旅行内容</view><viewv-show="currentIndex === 1">国外旅行内容</view><viewv-show="currentIndex === 2">城市漫步内容</view><viewv-show="currentIndex === 3">自然风光内容</view><viewv-show="currentIndex === 4">人文古迹内容</view></view></view></template><script>export default {  data() {return {tabList: [        { name'国内旅行' },        { name'国外旅行' },        { name'城市漫步' },        { name'自然风光' },        { name'人文古迹' }      ],currentIndex1    }  },methods: {    switchTab(index) {this.currentIndex = index    }  }}</script><stylescoped>.page-wrapper {width100%;min-height100vh;padding20rpx;box-sizing: border-box;}.tab-container {display: flex;align-items: center;justify-content: space-between;padding020rpx;height88rpx;border-radius44rpx;margin-bottom20rpx;background#f5f5f5;}.tab-list {display: flex;align-items: center;flex1;overflow-x: auto;white-space: nowrap;}.tab-item {font-size32rpx;font-weight500;color#999;padding020rpx;line-height88rpx;position: relative;transition: all 0.3s ease;flex-shrink0;}.tab-item.active {font-weight: bold;color#000;}.tab-item.active::after {content'';position: absolute;bottom8rpx;left50%;transformtranslateX(-50%);width40rpx;height6rpx;background#ff3b30;border-radius3rpx;}.tab-right {display: flex;align-items: center;gap10rpx;flex-shrink0;}.icon-item {width60rpx;height60rpx;display: flex;align-items: center;justify-content: center;}.icon-img {width40rpx;height40rpx;object-fit: contain;}.content-container {padding30rpx;font-size28rpx;color#333;}</style>
03
蓝色渐变 + 绿色指示器

蓝色清新渐变背景,无右侧图标,选中项底部绿色长条指示器,醒目不突兀,适合运动、工具类页面。

完整源码

<template><viewclass="page-wrapper"><viewclass="tab-container tab-container-3"><viewclass="tab-list"><viewv-for="(item, index) in tabList":key="index"class="tab-item":class="{ active: currentIndex === index }" @click="switchTab(index)">          {{ item.name }}</view></view></view><viewclass="content-container"><viewv-show="currentIndex === 0">跑步内容</view><viewv-show="currentIndex === 1">游泳内容</view><viewv-show="currentIndex === 2">瑜伽内容</view><viewv-show="currentIndex === 3">力量内容</view><viewv-show="currentIndex === 4">有氧内容</view><viewv-show="currentIndex === 5">其他内容</view></view></view></template><script>export default {  data() {return {tabList: [        { name'跑步' },        { name'游泳' },        { name'瑜伽' },        { name'力量' },        { name'有氧' },        { name'其他' }      ],currentIndex0    }  },methods: {    switchTab(index) {this.currentIndex = index    }  }}</script><stylescoped>.page-wrapper {width100%;min-height100vh;padding20rpx;box-sizing: border-box;backgroundlinear-gradient(90deg, #cce0ff 0%, #e6e6ff 50%, #cce0ff 100%);}.tab-container {display: flex;align-items: center;padding020rpx;height88rpx;border-radius44rpx;margin-bottom20rpx;backgroundlinear-gradient(to right, #e1f7fe#f0f9ff);}.tab-list {display: flex;align-items: center;flex1;overflow-x: auto;white-space: nowrap;}.tab-item {font-size32rpx;font-weight500;color#999;padding020rpx;line-height88rpx;position: relative;transition: all 0.3s ease;flex-shrink0;}.tab-item.active {font-weight: bold;color#000;}.tab-item.active::after {content'';position: absolute;bottom8rpx;left50%;transformtranslateX(-50%);width60rpx;height6rpx;background#07c160;border-radius3rpx;}.content-container {padding30rpx;font-size28rpx;color#333;}</style>

原创声明:本文为雪天前端原创技术文章,未经授权禁止转载、搬运

04
三等分 + 不滚动 + 搜索框

3 个 Tab 自动等分宽度、禁止横向滚动右侧自带圆角搜索框,黄色指示器,适合工具、分类、本地生活页面。

完整源码

<template><viewclass="page-wrapper"><viewclass="tab-container tab-container-5"><viewclass="tab-list no-scroll flex-equal"><viewv-for="(item, index) in tabList":key="index"class="tab-item":class="{ active: currentIndex === index }" @click="switchTab(index)">          {{ item.name }}</view></view><viewclass="search-box"><imageclass="search-icon-img"src="/static/xt-tabs/searchIcon.png"></image><inputtype="text"class="search-input"placeholder="搜索雪天前端" /></view></view><viewclass="content-container"><viewv-show="currentIndex === 0">新车内容</view><viewv-show="currentIndex === 1">评测内容</view><viewv-show="currentIndex === 2">导购内容</view></view></view></template><script>export default {  data() {return {tabList: [        { name'新车' },        { name'评测' },        { name'导购' }      ],currentIndex0    }  },methods: {    switchTab(index) {this.currentIndex = index    }  }}</script><stylescoped>.page-wrapper {width100%;min-height100vh;padding20rpx;box-sizing: border-box;backgroundlinear-gradient(90deg, #cce0ff 0%, #e6e6ff 50%, #cce0ff 100%);}.tab-container {display: flex;align-items: center;justify-content: space-between;padding020rpx;height88rpx;border-radius44rpx;margin-bottom20rpx;backgroundlinear-gradient(to right, #e6f7ff#fff7e6);}.tab-list {display: flex;align-items: center;flex1;}.tab-list.no-scroll {overflow: hidden !important;}.tab-list.flex-equal.tab-item {flex1;text-align: center;padding0;}.tab-item {font-size32rpx;font-weight500;color#999;line-height88rpx;position: relative;transition: all 0.3s ease;flex-shrink0;}.tab-item.active {font-weight: bold;color#000;}.tab-item.active::after {content'';position: absolute;bottom8rpx;left50%;transformtranslateX(-50%);width60rpx;height6rpx;background#ffdd00;border-radius3rpx;}.search-box {display: flex;align-items: center;background#ffffff;border-radius44rpx;padding020rpx;height64rpx;flex1;margin-left20rpx;}.search-icon-img {width36rpx;height36rpx;margin-right10rpx;object-fit: contain;}.search-input {flex1;font-size28rpx;color#333;background: transparent;border: none;outline: none;}.content-container {padding30rpx;font-size28rpx;color#333;}</style>

原创声明:本文为雪天前端原创技术文章,未经授权禁止转载、搬运

05
渐变色块选中

无背景设计,选中项直接变成渐变色圆角色块颜值极高,适合宠物、社交、女性向、年轻化项目

完整源码

<template><viewclass="page-wrapper"><viewclass="tab-container tab-container-6"><viewclass="tab-list"><viewv-for="(item, index) in tabList":key="index"class="tab-item":class="{ active: currentIndex === index }" @click="switchTab(index)">          {{ item.name }}</view></view></view><viewclass="content-container"><viewv-show="currentIndex === 0">猫咪内容</view><viewv-show="currentIndex === 1">狗狗内容</view><viewv-show="currentIndex === 2">鸟类内容</view><viewv-show="currentIndex === 3">水族内容</view><viewv-show="currentIndex === 4">小宠内容</view></view></view></template><script>export default {  data() {return {tabList: [        { name'猫咪' },        { name'狗狗' },        { name'鸟类' },        { name'水族' },        { name'小宠' }      ],currentIndex0    }  },methods: {    switchTab(index) {this.currentIndex = index    }  }}</script><stylescoped>.page-wrapper {width100%;min-height100vh;padding20rpx;box-sizing: border-box;backgroundlinear-gradient(90deg, #cce0ff 0%, #e6e6ff 50%, #cce0ff 100%);}.tab-container {background: transparent;padding0;}.tab-list {display: flex;align-items: center;flex1;overflow-x: auto;white-space: nowrap;}.tab-item {color#333;padding040rpx;line-height66rpx;font-size28rpx;transition: all 0.3s ease;flex-shrink0;}.tab-item.active {color#ffffff;backgroundlinear-gradient(to right, #e9abf4#87daff);border-radius20rpx;}.content-container {padding30rpx;font-size28rpx;color#333;}</style>

原创声明:本文为雪天前端原创技术文章,未经授权禁止转载、搬运

持续输出 uni-app / 小程序 / Vue 实战组件 与开发技巧,干货不断!

觉得有用记得 点赞 + 收藏 + 关注,后续更多优质组件持续更新~

大家觉得下期什么组件好,评论区见…

原创声明:本文为雪天前端原创技术文章,未经授权禁止转载、搬运

XT
往期推荐

uniapp 8种高级感搜索框源码,直接复制

PC端AI聊天页面(一键复制)

uniapp AI聊天页面

流程图库logicflow

一键登录页源码

一键登录页面

grid布局

那些好用的图标网站

uniapp 小程序生成骨架屏

你的点赞,在看, 满足我一切味蕾享受 !