Skip to content

Tabs ​

17:06

Description ​

A tab bar. Render tabs from list, with a built-in bottom indicator and badges. With is-scroll (default true) the tabs scroll horizontally and the active tab auto-scrolls to the center of the viewport; set it to false to distribute tabs evenly with no sliding. Tapping a tab emits change; update current externally to control the active tab.

Compatibility ​

PlatformSupport
App✅ Supported
H5✅ Supported
WeChat Mini Program✅ Supported

Examples ​

Basic Usage ​

Scrollable by default, the active tab auto-centers and triggers a change event on click.

View source
vue
<template>
    <ux-tabs :list="list" :current="current" @change="onChange" />
</template>

<script setup lang="uts">
import type { TabsItem } from '@/uni_modules/uview-pro-x';

const current = ref<number>(0);

const list: TabsItem[] = [
    { name: '标签一' },
    { name: '标签二' },
    { name: '标签三' },
    { name: '标签四' },
    { name: '标签五' }
];

const onChange = (index: number) => {
    current.value = index;
};
</script>

Disable Scroll ​

When is-scroll=false tabs are evenly distributed and cannot slide.

View source
vue
<template>
    <ux-tabs :list="list" :is-scroll="false" :current="current" @change="onChange" />
</template>

<script setup lang="uts">
import type { TabsItem } from '@/uni_modules/uview-pro-x';

const current = ref<number>(0);

const list: TabsItem[] = [
    { name: '标签一' },
    { name: '标签二' },
    { name: '标签三' }
];

const onChange = (index: number) => {
    current.value = index;
};
</script>

Custom Colors ​

Customize active/inactive text colors via active-color / inactive-color.

View source
vue
<template>
    <ux-tabs :list="list" active-color="#ffa500" inactive-color="#909399" :current="current" @change="onChange" />
</template>

<script setup lang="uts">
import type { TabsItem } from '@/uni_modules/uview-pro-x';

const current = ref<number>(0);

const list: TabsItem[] = [
    { name: '标签一' },
    { name: '标签二' },
    { name: '标签三' }
];

const onChange = (index: number) => {
    current.value = index;
};
</script>

Badge ​

The count field in list data displays a badge; is-dot switches to a dot.

View source
vue
<template>
    <ux-tabs :list="list" :is-scroll="false" :current="current" @change="onChange" />
</template>

<script setup lang="uts">
import type { TabsItem } from '@/uni_modules/uview-pro-x';

const current = ref<number>(0);

const list: TabsItem[] = [
    { name: '标签一', count: 5 },
    { name: '标签二', count: 20 },
    { name: '标签三', count: 100 },
    { name: '标签四' }
];

const onChange = (index: number) => {
    current.value = index;
};
</script>

API ​

Props ​

PropertyDescriptionTypeDefaultVersion
customStyleCustom root element stylestring | UTSJSONObject--
customClassCustom root element style classstring''-
isScrollWhether tabs can be dragged horizontallybooleantrue-
listTab arrayTabsItem[]--
currentIndex of the current active tabstring | number0-
heightNavbar height and line heightstring | number40-
fontSizeFont size, in pxstring | number15-
durationTransition duration, in secondsstring | number0.5-
activeColorTheme color of the selected itemstring''-
inactiveColorColor of unselected itemsstring''-
barWidthWidth of the bottom moving bar, in pxstring | number20-
barHeightHeight of the moving bar, in pxstring | number3-
gutterTotal left/right padding of a single tab, in pxstring | number20-
bgColorBackground color of the navbarstring''-
nameProperty read from each array object for the tab namestring'name'-
countProperty read from each array object for the badge countstring'count'-
offsetBadge position offsetnumber[]--
isDotWhether the badge is a dotbooleanfalse-
boldWhether the active tab font is boldbooleantrue-
activeItemStyleStyle of the current active tab itemUTSJSONObject--
showBarWhether to show the bottom indicatorbooleantrue-
barStyleCustom style of the bottom indicatorUTSJSONObject--
itemWidthTab widthstring | number'auto'-

Events ​

EventDescriptionParamsVersion
changeFires when a tab is tapped; params: index (the tapped tab index)index: number-

Slots ​

ux-tabs has no slots.

Notes ​

  • Tapping the already-active tab does not fire change again (the source returns early when the index is unchanged).
  • current is maintained externally (the component does not increment it internally); update it in the change callback.
  • When the length of list changes, the component resets the current index to 0.
  • The badge is driven by each list item's count; it is hidden when count is 0 or unset, and is-dot renders it as a dot.
  • In scroll mode (is-scroll=true) gutter becomes the tab's left/right padding; in non-scroll mode tabs are evenly distributed and item-width stays auto.
  • duration is in seconds; the indicator does not animate on its first appearance.