Skip to content

Tabs 标签组件

该组件,是一个tabs标签组件,在标签多的时候,可以配置为左右滑动,标签少的时候,可以禁止滑动。 该组件的一个特点是配置为滚动模式时,激活的tab会自动移动到组件的中间位置。

📌平台差异说明

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

🏯基本使用示例

html
<!-- 全局使用 -->
<hy-tabs :list="list"></hy-tabs>
ts
const list = [{ name: '全部' }, { name: '未核销' }, { name: '已核销' }];

显示徽标

  • 通过badge设置徽标属性,可以直接参考hy-badge组件属性配置
html
<template>
    <hy-tabs :list="list"></hy-tabs>
</template>
<script setup>
    const list = [
        { title: '全部', badge: { isDot: true } },
        { title: '未核销', badge: { value: 5 } },
        { title: '已核销' },
    ];
</script>

自定义读取键

  • 通过keyName自定义需要显示的值
html
<template>
    <hy-tabs :list="list" keyName="title"></hy-tabs>
</template>
<script setup>
    const list = [
        { title: '全部', content: { value: 123 } },
        { title: '未核销' },
        { title: '已核销' },
    ];
</script>

轮播图插槽自定义内容

html
<template>
    <hy-tabs :list="statusTabs" @clickTabs="clickTabs" @change="change">
        <template #default="{record}">{{record.value}}</template>
    </hy-tabs>
</template>

<script setup>
    const statusTabs = [
        { name: '全部', content: { value: 123 } },
        { name: '未核销' },
        { name: '已核销' },
    ];
    // 点击选项卡执行回调
    const clickTabs = () => {};
    // 滑动轮播图执行回调函数
    const change = () => {};
</script>

自定义轮播图

html
<template>
    <hy-tabs :list="statusTabs" @clickTabs="clickTabs" @change="change">
        <template #main>
            <!--自定义内容(没有轮播图)-->
        </template>
    </hy-tabs>
</template>

<script setup>
    const statusTabs = [{ name: '全部' }, { name: '未核销' }, { name: '已核销' }];
    // 点击选项卡执行回调
    const clickTabs = () => {};
    // 滑动轮播图执行回调函数
    const change = () => {};
</script>

API

Tabs Props

参数说明类型默认值
current当前选中标签的索引number0
list选项卡数组TabsItemVo[]-
keyName从list元素对象中读取的键名stringname
duration滑块移动一次所需的时间,单位 msnumber300
scrollable菜单是否可滚动booleanfalse
lineWidth滑块长度,数值默认单位pxstring|number20
lineHeight滑块高度,数值默认单位pxstring|number3
lineColor滑块颜色string-
lineBgSize滑块背景显示大小,当滑块背景设置为图片时使用string|numbercover
activeStyle菜单选择中时的样式CSSProperties-
inactiveStyle菜单非选中时的样式CSSProperties-
itemStyle菜单 item 的样式string-
badgeProps徽标props全局定义(list里的badge优先级高)BadgeProps-
swiperHeight轮播图高度,数值默认单位pxstring|numbercalc(100% - 44px)
isSwiper是否出现内容轮播booleanfalse
iconStyle标签左侧图标样式自定义CSSProperties-
customStyle定义需要用到的外部样式CSSProperties-
customClass自定义外部类名string-

Events

事件名说明回调参数
click点击标签时触发item: TabsItemVo, index: 标签索引值
longPress长按标签时触发item: TabsItemVo, index: 标签索引值
change标签索引改变时触发item: TabsItemVo, index: 标签索引值

Slots

插槽名说明接收值
default轮播图自定义content值record: TabsItemVo, index: 索引
left整体左侧插槽-
icontabs的图标record: TabsItemVo, index: 索引
contenttabs的内容record: TabsItemVo, index: 索引
right整体右侧插槽-
main自定义掉底部轮播图-

Typings

类型说明
ts
export interface TabsItemVo {
    /**
     * tab名称
     * */
    name: string;
    /**
     * 徽标接收的props
     * */
    badge?: HyBadgeProps;
    /**
     * 是否禁用
     * */
    disabled?: boolean;
    /**
     * swiper内容值
     * */
    content?: any;
    [key: string]: any;
}
03:29