t-tabbar
底部标签栏
t-tabbar 组件介绍
t-tabbar 用于组织全屏底部导航。每个 t-tabbar-item 同时定义一个导航项和对应的页面内容,组件通过 v-model 管理当前激活项。
t-tabbar 平台兼容
| Harmony | H5 | Android | iOS | 小程序 | UTS |
|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
t-tabbar 基础用法
将 v-model 绑定到当前索引。t-tabbar-item 的默认插槽是该 tab 的页面内容,首次切换后内容会保留,便于保留滚动位置和页面状态。
vue
<template>
<t-tabbar v-model="current">
<t-tabbar-item icon-path="grid"
selected-icon-path="grid-fill"
text="首页">
<scroll-view :class="[`f b`]"
:show-scrollbar="false">
<tui-theme-switch></tui-theme-switch>
<t-text>首页内容</t-text>
</scroll-view>
</t-tabbar-item>
<t-tabbar-item icon-path="setting"
selected-icon-path="setting-fill"
text="服务">
<scroll-view :class="[`f b`]"
:show-scrollbar="false">
<t-text>服务内容</t-text>
</scroll-view>
</t-tabbar-item>
<t-tabbar-item icon-path="account"
selected-icon-path="account-fill"
text="我的">
<view :class="[`f b`]">
<t-text>我的内容</t-text>
</view>
</t-tabbar-item>
</t-tabbar>
</template>
<script setup lang="uts">
const current = ref<number>(0)
</script>自定义中间按钮
没有传入 icon-path、selected-icon-path 和 text 时,可通过 bar 插槽完全自定义导航入口。中间按钮仍是一个 t-tabbar-item,点击后会自动切换到它对应的内容。
vue
<template>
<t-tabbar v-model="current">
<t-tabbar-item icon-path="grid"
selected-icon-path="grid-fill"
text="首页">
<view :class="[`f b`]"></view>
</t-tabbar-item>
<t-tabbar-item>
<view :class="[`f b`]">
<t-text>发布内容</t-text>
</view>
<template #bar>
<view :class="[`twhr-50 fc mt-n20 tbg-pn`]"
hover-class="o-0.7">
<t-icon :fore="true"
name="plus"
:class="[`sfwb s-12`]"
type="primary"></t-icon>
<t-text :fore="true"
:class="[`s-12`]"
type="primary">发布</t-text>
</view>
</template>
</t-tabbar-item>
<t-tabbar-item icon-path="account"
selected-icon-path="account-fill"
text="我的">
<view :class="[`f b`]"></view>
</t-tabbar-item>
</t-tabbar>
</template>
<script setup lang="uts">
const current = ref<number>(0)
</script>t-tabbar Props
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
v-model / model-value | 当前激活的 t-tabbar-item 索引,从 0 开始 | number | 0 |
type | 激活项主题类型,可选 info、primary、error、warning、success | string | 'primary' |
effect | 主题效果,可选 normal、dark、light、plain | string | 'normal' |
disabled | 是否禁用 | boolean | false |
hover | 是否启用点击效果 | boolean | false |
size | 通用尺寸属性 | string | 'medium' |
path | 通用跳转路径属性 | string | '' |
t-tabbar Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
update:modelValue | 当前激活项变化时触发;通常由 v-model 自动处理 | index: number |
t-tabbar Slots
| 插槽名 | 说明 |
|---|---|
default | 放置 t-tabbar-item 子组件 |