Skip to content

Tabs Component

This is a tabs component. When there are many tabs, it can be configured to slide left and right; when there are few tabs, sliding can be disabled. One feature of this component is that when configured in scroll mode, the active tab automatically moves to the center of the component.

📌Platform Differences

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯Basic Usage Examples

html
<!-- Global usage -->
<hy-tabs :list="list"></hy-tabs>
ts
const list = [{ name: 'All' }, { name: 'Not Redeemed' }, { name: 'Redeemed' }];

Displaying Badges

  • Set badge properties via badge; refer directly to the hy-badge component property configuration
html
<template>
    <hy-tabs :list="list"></hy-tabs>
</template>
<script setup>
    const list = [
        { title: 'All', badge: { isDot: true } },
        { title: 'Not Redeemed', badge: { value: 5 } },
        { title: 'Redeemed' },
    ];
</script>

Custom Read Key

  • Customize the value to display via keyName
html
<template>
    <hy-tabs :list="list" keyName="title"></hy-tabs>
</template>
<script setup>
    const list = [
        { title: 'All', content: { value: 123 } },
        { title: 'Not Redeemed' },
        { title: 'Redeemed' },
    ];
</script>

Swiper Slot Custom Content

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

<script setup>
    const statusTabs = [
        { name: 'All', content: { value: 123 } },
        { name: 'Not Redeemed' },
        { name: 'Redeemed' },
    ];
    // Callback executed when a tab is clicked
    const clickTabs = () => {};
    // Callback function executed when the swiper slides
    const change = () => {};
</script>

Custom Swiper

html
<template>
    <hy-tabs :list="statusTabs" @clickTabs="clickTabs" @change="change">
        <template #main>
            <!--Custom content (without swiper)-->
        </template>
    </hy-tabs>
</template>

<script setup>
    const statusTabs = [{ name: 'All' }, { name: 'Not Redeemed' }, { name: 'Redeemed' }];
    // Callback executed when a tab is clicked
    const clickTabs = () => {};
    // Callback function executed when the swiper slides
    const change = () => {};
</script>

API

Tabs Props

ParameterDescriptionTypeDefault
currentIndex of the currently selected tabnumber0
listTab arrayTabsItemVo[]-
keyNameKey name read from the list element objectsstringname
durationTime required for the slider to move once, in msnumber300
scrollableWhether the menu is scrollablebooleanfalse
lineWidthSlider length; default unit for numeric values is pxstring|number20
lineHeightSlider height; default unit for numeric values is pxstring|number3
lineColorSlider colorstring-
lineBgSizeSlider background display size, used when the slider background is set to an imagestring|numbercover
activeStyleStyle of the menu when selectedCSSProperties-
inactiveStyleStyle of the menu when not selectedCSSProperties-
itemStyleStyle of the menu itemstring-
badgePropsGlobal definition of badge props (badge in list takes higher priority)BadgeProps-
swiperHeightSwiper height; default unit for numeric values is pxstring|numbercalc(100% - 44px)
isSwiperWhether content swiping is enabledbooleanfalse
iconStyleCustom style for the icon on the left side of the tabCSSProperties-
customStyleDefine external styles to be usedCSSProperties-
customClassCustom external class namestring-

Events

Event NameDescriptionCallback Parameters
clickTriggered when a tab is clickeditem: TabsItemVo, index: tab index value
longPressTriggered when a tab is long-presseditem: TabsItemVo, index: tab index value
changeTriggered when the tab index changesitem: TabsItemVo, index: tab index value

Slots

Slot NameDescriptionReceived Values
defaultCustom content value for the swiperrecord: TabsItemVo, index: index
leftSlot for the overall left side-
iconTab iconrecord: TabsItemVo, index: index
contentTab contentrecord: TabsItemVo, index: index
rightSlot for the overall right side-
mainCustom bottom swiper-

Typings

Type Descriptions
ts
export interface TabsItemVo {
    /**
     * Tab name
     * */
    name: string;
    /**
     * Props received by the badge
     * */
    badge?: HyBadgeProps;
    /**
     * Whether disabled
     * */
    disabled?: boolean;
    /**
     * Swiper content value
     * */
    content?: any;
    [key: string]: any;
}
03:29