TabBar 底部导航
uni-appH5微信小程序App
移动端底部导航栏,支持图标、角标、固定定位和 v-model。
何时使用
移动端一级导航,3-5 个平级页面的底部切换。
何时不使用
页面内局部 tab 切换(用 Tabs);层级返回导航用 NavBar。
本文档为 uni-app 端组件契约;Web 端同名组件 API 可能略有差异,请以对应包文档为准。下方手机预览实时运行 uni-app H5 演示。
9:41
TabBar 底部导航 · uni-app H5 实时运行 新窗口打开
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue | string | "" | 激活项 name(v-model) |
items | TabBarItem[] | [] | 标签项:{ name, label, icon?, badge? };icon 内置 home/menu/star/user,未知名称显示圆点占位;badge 为 'dot' 显示小红点,其余显示数字胶囊 |
fixed | boolean | false | 吸底固定,padding-bottom 自动叠加 --rn-safe-area-bottom |
Events
| 名称 | 载荷 | 说明 |
|---|---|---|
update:modelValue | string | 点击标签项时触发,payload 为该项 name |
change | string | 激活项变化时触发(点击当前项不触发) |
示例
基础用法
vue
<TabBar v-model="active" :items="tabbarItems" />带徽标
vue
<TabBar v-model="active" :items="[{ name: 'home', label: '首页', icon: 'home' }, { name: 'msg', label: '消息', icon: 'bell', badge: 6 }, { name: 'user', label: '我的', icon: 'user' }]" />受控切换
vue
<view class="row">
<Button size="sm" variant="ghost" @click="active = 'home'">首页</Button>
<Button size="sm" variant="ghost" @click="active = 'menu'">菜单</Button>
<Button size="sm" variant="ghost" @click="active = 'user'">我的</Button>
</view>
<TabBar v-model="active" :items="tabbarItems" style="margin-top:12px" />