Skip to content

引入组件

局部引入

ts
// parent.vue
const FTabbar = defineAsyncComponent(() => import('@/components/formaui/f-tabbar/f-tabbar.vue'))

基础用法

items属性:标签栏选项列表

html
<f-tabbar v-model="activeIndex" :items="items" @item-click="handleItemClick" />
ts
import { ref } from 'vue'

const activeIndex = ref(0)
const items = [
  { label: '首页', value: 'home', icon: 'home', activeIcon: 'home-fill' },
  { label: '分类', value: 'category', icon: 'category', activeIcon: 'category-fill' },
  { label: '购物车', value: 'cart', icon: 'cart', activeIcon: 'cart-fill', badge: 2 },
  { label: '我的', value: 'mine', icon: 'people', activeIcon: 'people-fill', isBadgeDot: true, badge: 1 }
]

const handleItemClick = (detail: { index: number; value?: string | number }) => {
  activeIndex.value = detail.index
}

isHump属性:中间凸起按钮(默认false

中间项需设置 isHump: true,并开启组件级 is-hump

html
<f-tabbar v-model="activeIndex" :items="humpItems" is-hump @item-click="handleItemClick" />
ts
const humpItems = [
  { label: '首页', value: 'home', icon: 'home', activeIcon: 'home-fill' },
  { label: '分类', value: 'category', icon: 'category', activeIcon: 'category-fill' },
  { label: '发布', value: 'publish', icon: 'plus', activeIcon: 'plus', isHump: true },
  { label: '消息', value: 'message', icon: 'message', activeIcon: 'message-fill' },
  { label: '我的', value: 'mine', icon: 'people', activeIcon: 'people-fill' }
]

showLine属性:顶部分割线(默认true

html
<f-tabbar v-model="activeIndex" :items="items" :show-line="false" />

activeColor属性:选中颜色

html
<f-tabbar v-model="activeIndex" :items="items" active-color="#16479D" />

图片图标:使用 iconPath / selectedIconPath 代替字体图标

html
<f-tabbar v-model="activeIndex" :items="imageItems" />
ts
const imageItems = [
  { label: '首页', iconPath: '/static/tab/home.png', selectedIconPath: '/static/tab/home-active.png' },
  { label: '我的', iconPath: '/static/tab/mine.png', selectedIconPath: '/static/tab/mine-active.png' }
]

插槽

名称说明
--

属性

名称类型说明默认值
v-modelnumber当前选中项索引0
itemsFTabbarItem[]标签栏选项列表-
textColorstring文字颜色#666666
activeColorstring选中文字/图标颜色主题色
bgColorstring背景颜色#FFFFFF
isHumpboolean是否启用中间凸起样式false
iconSizestring图标尺寸52rpx
isFixedboolean是否固定在底部true
badgeColorstring角标文字颜色#FFFFFF
badgeBgColorstring角标背景颜色主题危险色
showLineboolean是否显示顶部分割线true
isBackdropFilterboolean是否开启背景模糊false
zIndexnumber | string固定定位 z-index9999

FTabbarItem

名称类型说明默认值
labelstring标签文字-
valuestring | number选项值索引
iconstring字体图标名称-
activeIconstring选中态字体图标-
iconPathstring默认图片路径-
selectedIconPathstring选中态图片路径-
iconSizestring单项图标尺寸-
isHumpboolean是否为凸起按钮false
pagePathstring页面路径-
verifyboolean切换前是否校验-
badgenumber | string角标内容-
isBadgeDotboolean角标是否为圆点false

事件

事件名说明回调参数
itemClick点击标签项时{ index, value, isHump, pagePath, verify }

方法

方法名说明传入参数
---