更新记录
1.0.5(2026-07-26) 下载此版本
- 【新增】
v-model:current受控选中,支持外部设置初始选中项与程序化切换 - 【新增】item 级角标系统:
badge(数字/文本,支持badgeMax上限显示 99+)、dot(红点) - 【新增】
beforeChange切换守卫,支持返回Promise,可用于登录拦截等场景 - 【新增】
autoRoute路由联动:item 配置pagePath+switchMode后点击自动跳转;配套useTabBar组合式函数实现多页面选中态同步 - 【新增】字体图标支持:item 配置
iconType: 'font'后icon/active传字体图标 class - 【新增】样式配置:
background、textColor、activeTextColor、fontSize、height、zIndex、duration、fixed、placeholder - 【新增】item 支持
disabled禁用;组件暴露switchTo(index)编程式切换方法 - 【优化】布局改为百分比自适应,修复宽屏/iPad/折叠屏下 750rpx 硬编码导致的错位
- 【优化】角标锚定图标右上角并随选中图标一同浮入圆钮,自带底栏同色描边;修复 tab 数量变化时角标偏移;图片图标增加
aspectFit与默认尺寸 - 【修复】移除生产环境调试日志与无效样式;
data为空时的除零保护 - 【兼容】旧版
corner+cornerMark用法与change事件的currenIndex字段继续可用(已标记废弃,建议迁移)
1.0.3(2025-12-02) 下载此版本
1.更新角标功能 2.简化示例
1.0.2(2025-08-07) 下载此版本
1.增加参数说明
查看更多平台兼容性
uni-app
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| × | √ | √ | - | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - | - | - | - |
其他
| 多语言 | 暗黑模式 | 宽屏模式 |
|---|---|---|
| × | × | √ |
sk-tab-bar
组件形式的凹陷弧形 tabBar,选中项自动上浮进入圆形按钮,凹槽随切换平滑移动。
- ✅
v-model:current受控选中,支持外部设置初始项与程序化切换 - ✅ item 级角标(数字 / 红点 / 99+ 上限)
- ✅
beforeChange切换守卫(支持异步,可做登录拦截) - ✅
autoRoute路由联动 +useTabBar多页面选中态同步 - ✅ 作用域插槽完全自定义 tab 内容
- ✅ 图片图标 / 字体图标双模式
- ✅ 主题样式全量可配,百分比布局自适应宽屏
- ✅ TypeScript 类型导出
扫码体验
基础用法
组件形式 tabBar 不依赖 pages.json 的原生 tabBar 配置;如需页面跳转请使用
autoRoute或在change回调中自行处理。
<template>
<sk-tab-bar v-model:current="current" :data="list" @change="onChange" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import type { SkTabBarItem, SkTabBarChangeEvent } from '@/uni_modules/sk-tab-bar/components/sk-tab-bar/sk-tab-bar.type'
import icon1 from '@/static/66.png'
import icon1Active from '@/static/icon1.png'
import icon2 from '@/static/77.png'
import icon2Active from '@/static/icon2.png'
const current = ref(0)
const list = ref<SkTabBarItem[]>([
{ text: '首页', icon: icon1, active: icon1Active },
{ text: '资源列表', icon: icon2, active: icon2Active }
])
const onChange = (e: SkTabBarChangeEvent) => {
console.log('切换到:', e.currentIndex, e.text)
}
</script>
角标 / 红点
角标配置在每个 item 上,互不影响;数字超过 badgeMax(默认 99)显示 99+,为 0 或空时自动隐藏。
<sk-tab-bar :data="list" :badge-max="99" />
const list = ref<SkTabBarItem[]>([
{ text: '首页', icon: icon1, active: icon1Active },
{ text: '消息', icon: icon2, active: icon2Active, badge: 128 }, // 显示 99+
{ text: '我的', icon: icon3, active: icon3Active, dot: true } // 红点
])
切换拦截(beforeChange)
返回 false 或 Promise<false> 时阻止切换,常用于登录校验:
<sk-tab-bar :data="list" :before-change="beforeChange" />
const beforeChange = async (index: number, item: SkTabBarItem) => {
if (index === 2 && !isLogin.value) {
uni.navigateTo({ url: '/pages/login/index' })
return false
}
return true
}
路由联动(autoRoute)
item 配置 pagePath 后点击自动跳转;多页面场景配合 useTabBar 同步选中态:
<sk-tab-bar auto-route v-model:current="current" :data="items" @change="e => setCurrent(e.currentIndex)" />
import { useTabBar } from '@/uni_modules/sk-tab-bar/components/sk-tab-bar/use-tab-bar'
// 每个页面调用同一份共享状态
const { current, items, setCurrent } = useTabBar([
{ text: '首页', icon: icon1, active: icon1Active, pagePath: '/pages/home/index', switchMode: 'reLaunch' },
{ text: '我的', icon: icon2, active: icon2Active, pagePath: '/pages/mine/index', switchMode: 'reLaunch' }
])
自定义内容(插槽)
通过 item 作用域插槽完全接管 tab 渲染:
<sk-tab-bar :data="list">
<template #item="{ item, index, active }">
<image :src="active ? item.active : item.icon" style="width: 40px; height: 40px" />
<text v-if="!active">{{ item.text }}</text>
</template>
</sk-tab-bar>
字体图标
const list = ref<SkTabBarItem[]>([
// icon/active 传字体图标 class,width 作为字号
{ text: '首页', iconType: 'font', icon: 'iconfont icon-home', active: 'iconfont icon-home-fill', width: '48rpx' }
])
主题定制
<sk-tab-bar
:data="list"
background="#1f1f1f"
text-color="#999"
active-text-color="#fff"
icon-background-color="#07c160"
outer-aperture-border-color="#141414"
height="130rpx"
:duration="300"
placeholder
/>
API
Props
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| data | SkTabBarItem[] |
[] |
tab 数据源 |
| current | Number |
0 |
当前选中下标,支持 v-model:current |
| outerApertureBorderColor | String |
#f2f3f7 |
弧形外光圈颜色,需与页面背景一致 |
| iconBackgroundColor | String |
rgb(3, 3, 3) |
选中圆形按钮背景色 |
| background | String |
#fff |
tabBar 背景色 |
| textColor | String |
#222 |
文字颜色 |
| activeTextColor | String |
#222 |
选中文字颜色 |
| fontSize | String |
26rpx |
文字字号 |
| height | String |
120rpx |
tabBar 高度,同时决定圆形按钮直径 |
| zIndex | Number |
10 |
层级 |
| duration | Number |
500 |
切换动画时长(ms) |
| fixed | Boolean |
true |
是否固定在页面底部 |
| placeholder | Boolean |
false |
fixed 时是否生成同高占位,防止遮挡页面内容 |
| badgeMax | Number |
99 |
数字角标上限,超出显示 badgeMax+ |
| autoRoute | Boolean |
false |
点击后是否按 item.pagePath 自动跳转 |
| beforeChange | (index, item) => boolean \| Promise<boolean> |
- | 切换守卫,返回 false 阻止切换 |
| corner | String \| Number |
- | ⚠️ 已废弃,请使用 item.badge |
SkTabBarItem
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| text | String |
- | 按钮文字 |
| icon | String |
- | 未选中图标(图片地址或字体图标 class) |
| active | String |
- | 选中图标(图片地址或字体图标 class) |
| iconType | 'image' \| 'font' |
image |
图标类型 |
| width | String |
36px |
图标宽度(字体图标时作为字号) |
| height | String |
36px |
图标高度 |
| badge | String \| Number |
- | 角标内容,0 或空时隐藏 |
| dot | Boolean |
false |
红点角标,优先级高于 badge |
| disabled | Boolean |
false |
是否禁用 |
| pagePath | String |
- | 页面路径,配合 autoRoute 使用 |
| switchMode | 'switchTab' \| 'reLaunch' \| 'navigateTo' \| 'redirectTo' |
reLaunch |
跳转方式 |
| cornerMark | Boolean |
- | ⚠️ 已废弃,请使用 badge |
Events
| 事件名 | 回调参数 | 说明 |
|---|---|---|
| change | SkTabBarChangeEvent(item 全量字段 + currentIndex) |
tab 切换后触发 |
| update:current | index: number |
选中变化,配合 v-model:current |
Slots
| 插槽名 | 作用域参数 | 说明 |
|---|---|---|
| item | { item, index, active } |
自定义每个 tab 的内容 |
Methods(ref 调用)
| 方法名 | 参数 | 说明 |
|---|---|---|
| switchTo | index: number |
编程式切换,会执行 beforeChange 守卫与事件流程 |
从旧版本迁移
1.0.5 完全兼容旧版用法,以下 API 已标记废弃,建议迁移:
| 旧用法 | 新用法 |
|---|---|
组件级 corner + item cornerMark |
item 级 badge / dot |
change 回调中的 currenIndex |
currentIndex |

收藏人数:
https://github.com/KTBOY/shukelab
下载插件并导入HBuilderX
下载示例项目ZIP
赞赏(1)
下载 155
赞赏 0
下载 12496499
赞赏 1939
赞赏
京公网安备:11010802035340号