Skip to content

引入组件

局部引入

ts
// parent.vue
const FBottomNav = defineAsyncComponent(() => import('@/components/formaui/f-bottom-nav/f-bottom-nav.vue'))

基础用法

items属性:导航项列表

底部导航支持三种 mode1 选中切换、2 点击操作、3 弹出子菜单。

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

const activeIndex = ref(0)
const items = [
  { label: '首页', value: 'home', mode: 1 },
  { label: '分类', value: 'category', mode: 1 },
  { label: '购物车', value: 'cart', mode: 2 },
  {
    label: '更多',
    value: 'more',
    mode: 3,
    subItems: [
      { label: '扫一扫', value: 'scan' },
      { label: '消息中心', value: 'message' },
      { label: '设置', value: 'setting' }
    ]
  }
]

const handleItemClick = (detail) => {
  if (detail.menu === 'main' && detail.mode === 1) {
    activeIndex.value = detail.index
  }
}

mode=1:选中切换

点击后组件会通过 v-model 更新 activeIndex,并触发 itemClick

mode=2:点击操作

仅触发 itemClick,不自动切换选中项。

mode=3:弹出子菜单

点击主项展开 subItems,点击子项后关闭菜单并触发 itemClickmenusub)。

图片图标:iconPath / selectedIconPath

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

isDarkMode属性:暗黑模式(默认false

开启后使用内置暗色配色,自定义颜色失效。

html
<f-bottom-nav v-model="activeIndex" :items="items" is-dark-mode />

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

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

isFixed属性:是否固定底部(默认true

html
<f-bottom-nav v-model="activeIndex" :items="items" :is-fixed="false" />

插槽

名称说明
暂无

属性

属性名类型说明默认值
v-modelnumber当前选中索引(mode=1 项)0
itemsFBottomNavItem[]导航项列表[]
textColorstring默认文字颜色#666666
activeColorstring选中文字颜色主题色
fontSizestring文字大小28rpx
isTabBoldboolean选中项是否加粗true
bgColorstring背景色#F8F8F8
isSplitLineShortbooleanitem 分割线是否缩短true
subMenuTextColorstring子菜单文字颜色#0B1D4A
subMenuFontSizestring子菜单文字大小28rpx
subMenuBgColorstring子菜单背景色#FFFFFF
isSubMenuHoverboolean子菜单点击态true
isFixedboolean是否固定底部true
showLineboolean是否显示顶部分割线true
isDarkModeboolean是否暗黑模式false

FBottomNavItem

属性名类型说明
labelstring导航文字
valuestring | number自定义参数,回调时返回
iconPathstring默认图标图片
selectedIconPathstring选中态图标(mode=1
colorstring单项文字颜色
mode1 | 2 | 3交互模式
popupLeftstring子菜单水平偏移,默认 50%
subItemsFBottomNavSubItem[]子菜单列表

FBottomNavSubItem

属性名类型说明
labelstring子菜单文字
valuestring | number自定义参数

事件

事件名说明回调参数
itemClick点击主菜单或子菜单FBottomNavClickDetail

FBottomNavClickDetail

字段类型说明
menu'main' | 'sub'主菜单或子菜单
modenumber对应 item 的 mode
indexnumber主菜单索引
subIndexnumber子菜单索引(menu=sub 时)
valuestring | number自定义参数