Skip to content

Tabbar 底部导航栏 ​

用于页面底部的一级导航。支持选中态图标、角标、安全区、固定定位和中间凸起按钮。

使用建议 ​

Tabbar 只用于应用的一级目的地,项目应保持固定的项目数量与顺序。临时操作、筛选或页面内切换分别使用 Button、DropMenu 或 Tabs。

平台兼容性 ​

H5App微信小程序支付宝小程序
√√√√

基础用法 ​

vue
<script setup lang="ts">
import { ref } from 'vue';

const current = ref('home');
const items = [
    { key: 'home', text: '首页', iconPath: 'home', selectedIconPath: 'home-fill' },
    { key: 'category', text: '分类', iconPath: 'list', selectedIconPath: 'list-dot' },
    { key: 'mine', text: '我的', iconPath: 'account', selectedIconPath: 'account-fill', badge: 3 }
];
</script>

<template>
    <snake-tabbar :items="items" :current="current" @change="current = $event" />
</template>

通过 v-model 按索引维护选中项:

vue
<snake-tabbar v-model="currentIndex" :items="items" />

为中间项设置 mid-button,并在对应项中设置 midButton: true,即可显示凸起按钮:

vue
<snake-tabbar :items="items" :current="current" mid-button />

<!-- items 中的中间项 -->
{ key: 'publish', text: '发布', iconPath: 'plus', midButton: true }

无障碍 ​

  • 每一项都提供简短且唯一的文字标签,不能只显示图标。
  • 当前项除颜色外还应保持选中状态语义;角标数量变化需要有对应的业务提示。
  • 中间凸起按钮若代表“发布”等操作,应使用动作文案,不要伪装成导航目的地。

API ​

Props ​

参数说明类型默认值
items / list导航项列表;优先使用 itemsTabbarItem[][]
current当前激活项的 keystring | number''
modelValue通过 v-model 绑定的激活项索引string | number0
show / fixed显示导航栏、固定在页面底部booleantrue / true
safeAreaInsetBottom是否预留底部安全区booleantrue
activeColor / inactiveColor激活和未激活颜色string主色 / 弱化文字色
bgColor背景色string表面背景色
borderTop是否显示顶部边框booleantrue
hideTabBar挂载时隐藏原生 tabBar;非原生 tabBar 页安全忽略booleantrue
beforeSwitch切换拦截器;返回 true 或 resolve 的 Promise 才会切换(index) => boolean | Promise-
midButton是否启用中间凸起按钮booleanfalse
iconSize / midButtonSize常规图标和凸起图标尺寸,数字单位为 rpxstring | number40 / 100
textSize / gap文字尺寸、图标与文字间距,数字单位为 rpxstring | number22 / 5
height导航栏高度,数字单位为 rpxstring | number104
zIndex固定导航栏层级number120
customClass / customStyle根节点类名和样式string / StyleValue'' / ''

原生 tabBar ​

将 snake-tabbar 放在 pages.json 的原生 tabBar 页面时,组件默认调用 uni.hideTabBar(),由自定义栏替代原生栏。普通页面也可以复用组件:该 API 的预期失败会被内部安全处理。传入 :hide-tab-bar="false" 可保留原生 tabBar。

TabbarItem ​

参数说明类型默认值
key导航项唯一标识string | number当前索引
text导航文字string''
icon / iconPath未选中图标名称,iconPath 优先string''
selectedIconPath选中图标名称string未选中图标
customIcon图标字体前缀;传字符串时直接作为前缀boolean | stringfalse
pagePath页面路径;传入后按当前页面自动确定激活项string''
midButton是否作为中间凸起项booleanfalse
width单项宽度;任一项设置后其余项填充剩余空间string | number自动均分
iconSize / textSize / gap单项图标尺寸、文字尺寸、间距string | number继承组件属性
badge / count角标文字或数量,badge 优先string | numberundefined
isDot是否仅显示点状角标booleanfalse
disabled是否禁用点击booleanfalse

Events ​

事件名触发时机参数
change点击未禁用的导航项key, item
update:modelValue点击无 pagePath 的导航项时index

pagePath 存在时,组件会调用 uni.switchTab();不需要由父组件重复处理跳转。beforeSwitch 返回 false 或 rejected Promise 时,组件不发出事件、不更新值、也不跳转。

主题变量 ​

变量名说明
--snake-color-primary默认激活颜色
--snake-color-text-muted默认未激活颜色
--snake-color-surface导航栏和中间按钮背景色
--snake-color-surface-muted按压背景色
--snake-color-divider顶部边框和中间按钮描边色
--snake-color-error角标背景色

为 uni-app 商城与 CMS 场景设计