Skip to content

底部导航栏组件

底部导航栏,用于在不同页面之间进行切换。

📌平台差异说明

APP(vue)H5微信小程序支付宝小程序

🏯基本使用示例

vue
<template>
    <hy-tabbar-group v-model="current" @change="onChange">
        <hy-tabbar-item title="首页" icon="home"></hy-tabbar-item>
        <hy-tabbar-item title="分类" icon="class"></hy-tabbar-item>
        <hy-tabbar-item title="我的" icon="mine"></hy-tabbar-item>
    </hy-tabbar-group>
</template>

<!-- 底部固定的tabbar测试 -->
<hy-tabbar v-model="fixedCurrent" :list="list" activeColor="red"></hy-tabbar>
ts
import { ref } from 'vue';

const current = ref(0)
const fixedCurrent = ref('0')
const list = [
    { name: '首页', icon: IconConfig.HOME },
    { name: '分类', icon: IconConfig.HOME },
    { name: '购物车', icon: IconConfig.HOME, badge: 10 },
    { name: '我的', icon: IconConfig.HOME }
]
javascript
import { IconConfig } from "hy-app";

const list = [
    { name: "首页", icon: IconConfig.HOME },
    { name: "分类", icon: IconConfig.HOME },
    { name: "购物车", icon: IconConfig.HOME, badge: 10 },
    { name: "我的", icon: IconConfig.HOME },
];

徽标提示

  • badgeProp: 接收badge参数

注意

isDot为true时候value必须要有值,没有数字时候可以填写true,否则不会显示

html
<hy-tabbar-group
    :custom-style="{ marginBottom: '20px' }"
    :badgeProps="{ isDot: true }"
    v-model="current"
    @change="onChange"
>
  <hy-tabbar-item title="首页" icon="home"></hy-tabbar-item>
  <hy-tabbar-item title="分类" icon="class"></hy-tabbar-item>
  <hy-tabbar-item title="我的" icon="mine" :value="true"></hy-tabbar-item>
</hy-tabbar-group>

<hy-tabbar-group v-model="current" @change="onChange">
  <hy-tabbar-item title="首页" icon="home" :value="10"></hy-tabbar-item>
  <hy-tabbar-item title="分类" icon="class"></hy-tabbar-item>
  <hy-tabbar-item title="我的" icon="mine"></hy-tabbar-item>
</hy-tabbar-group>

圆角导航栏

html
<hy-tabbar-group v-model="current" @change="onChange" shape="circle">
    <hy-tabbar-item title="首页" icon="home"></hy-tabbar-item>
    <hy-tabbar-item title="分类" icon="class"></hy-tabbar-item>
    <hy-tabbar-item title="我的" icon="mine"></hy-tabbar-item>
</hy-tabbar-group>

圆角导航栏

html
<hy-tabbar-group
        v-model="current"
        @change="onChange"
        activeColor="red"
        inactiveColor="green"
>
    <hy-tabbar-item title="首页" icon="home"></hy-tabbar-item>
    <hy-tabbar-item title="分类" icon="class"></hy-tabbar-item>
    <hy-tabbar-item title="我的" icon="mine"></hy-tabbar-item>
</hy-tabbar-group>

icon插槽

html
<hy-tabbar-group v-model="current" @change="onChange">
    <hy-tabbar-item title="首页" icon="home">
        <template #icon>
            <hy-image :src="config.avatar" width="30" height="30"></hy-image>
        </template>
    </hy-tabbar-item>
    <hy-tabbar-item title="分类" icon="class"></hy-tabbar-item>
    <hy-tabbar-item title="我的" icon="mine"></hy-tabbar-item>
</hy-tabbar-group>

API

Tabbar Props

参数说明类型默认值
modelValue选中项的索引值number0
list导航栏数据集合array[]
fixed是否固定在底部booleantrue
placeholder是否显示占位元素booleanfalse
color图标和字体颜色string-
baseBgColor轨道颜色string-
bgColor背景颜色string-
activeColor激活圆形背景颜色string-
badgeProps徽标API属性HyBadgeProps-
customStyle定义需要用到的外部样式CSSProperties-
customClass自定义外部类名string-

list

参数说明类型默认值
nametabBar名称string-
iconicon图标或者图片string-
badge徽标值number-

TabbarGroup Props

参数说明类型默认值
modelValue选中项的索引值number0
fixed是否固定在底部booleanfalse
border是否显示顶部边框booleantrue
placeholder是否显示占位元素booleantrue
shape导航栏的形状string'square'
bgColor背景颜色string-
activeColor激活颜色string-
inactiveColor非激活颜色string-
safeAreaInsetBottom底部安全区域适配 - 主要用于iPhone X及以上机型booleantrue
iconSize图标大小string|number-
fontSize文字大小string|number-
badgeProps徽标部分属性HyBadgeProps-
zIndexz-index层级number10086
customStyle定义需要用到的外部样式CSSProperties-
customClass自定义外部类名string-

TabbarItem Props

参数说明类型默认值
icon图标string-
title标题string-
name唯一标识string|number-
value徽标显示值,当为徽标为点时候,必须要value设置true或者有值string|number|boolean-

Events

Tabbar Emits

事件名说明回调参数
change更新选中索引value: number

TabbarGroup Emits

事件名说明回调参数
change更新选中索引{value: string | number}

Slots

Tabbar Slots

注意

tabbar图标插槽在小程序是没有效果

插槽名说明接收值
icon图标插槽-

TabbarItem Slots

插槽名说明接收值
icon图标插槽-
06:21