Skip to content

Tabs ​

Tab component for switching between different content areas.

Component Types ​

Basic Usage ​

v-model accepts a numeric index or a string or numeric name.

html
<wd-tabs v-model="tab1" @change="handleChange">
  <block v-for="item in 4" :key="item">
    <wd-tab :title="`Tab${item}`">
      <view class="content">Content{{ tab1 + 1 }}</view>
    </wd-tab>
  </block>
</wd-tabs>
ts
const tab1 = ref(0)

function handleChange(event) {
  console.log(event)
}

Name Matching ​

Set name on wd-tab to select a tab by its string or numeric name. Names use strict equality: the number 1 and the string '1' are different names.

html
<wd-tabs v-model="tab">
  <wd-tab v-for="item in tabs" :key="item" :title="item" :name="item">
    <view class="content">Content{{ tab }}</view>
  </wd-tab>
</wd-tabs>
ts
const tabs = ref(['this', 'is', 'a', 'individual', 'example'])
const tab = ref('a')

Numeric names can be negative, zero, or nonconsecutive. Bind them to wd-tab with :name:

html
<wd-tabs v-model="numericTab" swipeable>
  <wd-tab v-for="name in numericTabs" :key="name" :name="name" :title="`Tab${name}`" :disabled="name === 0">
    <view class="content">Content{{ name }}</view>
  </wd-tab>
</wd-tabs>
ts
const numericTabs = [-1, 0, 1, 3, 2]
const numericTab = ref(-1)

Tabs without a name use their zero-based index as their identifier. Explicitly set names take precedence; if no name matches, a valid numeric index can still select a tab. Unmatched names and invalid indices fall back to the first tab, while disabled tabs cannot be activated. Switching tabs updates the bound value to the selected tab's name, or its index if no name is set.

If an explicit numeric name equals an unnamed tab's index, the explicit name takes precedence. For example, if the first tab has no name and the second has :name="0", binding 0 selects the second tab. However, both tabs then have the identifier 0, so the component logs a warning. A single bound value cannot distinguish these tabs, and reliable two-way binding is not supported with duplicate identifiers. All identifiers (explicit names or default indices) must be unique. When mixing named and unnamed tabs, consider assigning a unique name to every tab.

Use Badge ​

Add badges to tabs through badge-props.

html
<wd-tabs v-model="tabWithBadge">
  <wd-tab v-for="(item, index) in tabsWithBadge" :key="index" :title="item.title" :badge-props="item.badgeProps">
    <view class="content">{{ item.title }} Badge</view>
  </wd-tab>
</wd-tabs>

Component States ​

Sticky Layout ​

Setting sticky enables sticky layout, can be combined with offset-top to control sticky offset.

html
<wd-tabs v-model="tab2" sticky>
  <wd-tab v-for="item in 4" :key="item" :title="`Tab${item}`">
    <view class="content">Content{{ tab2 + 1 }}</view>
  </wd-tab>
</wd-tabs>

Disable Tab ​

Disable individual tabs through the disabled property of wd-tab.

html
<wd-tabs v-model="tab3">
  <wd-tab v-for="item in 4" :key="item" :title="`Tab${item}`" :disabled="item === 1">
    <view class="content">Content{{ tab3 + 1 }}</view>
  </wd-tab>
</wd-tabs>

Component Styles ​

Bottom Bar Style ​

Adjust bottom bar appearance through line-theme, supports normal, text, underline, dot.

html
<wd-tabs v-model="tabLineTheme.normal" line-theme="normal">
  <wd-tab v-for="item in 4" :key="item" :title="`normal ${item}`">
    <view class="content">Content{{ item }}</view>
  </wd-tab>
</wd-tabs>

Special Styles ​

Click Event ​

Listen to click to get information about the currently clicked tab.

html
<wd-tabs v-model="tab4" @click="handleClick" @change="handleChange">
  <wd-tab v-for="item in 4" :key="item" :title="`Tab${item}`">
    <view class="content">Content{{ tab4 + 1 }}</view>
  </wd-tab>
</wd-tabs>
ts
function handleClick({ index, name }) {
  console.log(index, name)
}

Switch Animation ​

Setting animated enables content switch animation.

html
<wd-tabs v-model="tab8" animated>
  <wd-tab v-for="item in 4" :key="item" :title="`Tab${item}`">
    <view class="content">Content{{ tab8 + 1 }}</view>
  </wd-tab>
</wd-tabs>

Gesture Swipe ​

Setting swipeable enables gesture swipe, often used in combination with animated.

html
<wd-tabs v-model="tab5" swipeable animated>
  <wd-tab v-for="item in 4" :key="item" :title="`Tab${item}`">
    <view class="content">Content{{ tab5 + 1 }}</view>
  </wd-tab>
</wd-tabs>

Overflow Scroll and Navigation Map ​

After the number of tabs exceeds slidable-num, scrolling is enabled. After exceeding map-num, a navigation map is displayed. Setting slidable to always enables always left-aligned scrolling.

html
<wd-tabs v-model="tab6">
  <wd-tab v-for="item in 7" :key="item" :title="`Tab${item}`">
    <view class="content">Content{{ tab6 + 1 }}</view>
  </wd-tab>
</wd-tabs>

<wd-tabs v-model="tab9" slidable="always">
  <wd-tab v-for="item in 5" :key="item" :title="`Large Tab${item}`">
    <view class="content">Content{{ tab9 + 1 }}</view>
  </wd-tab>
</wd-tabs>

Use in Popup ​

In WeChat Mini Program and other scenarios, after the popup opens, you can call updateLineStyle to update the active item style.

html
<wd-button @click="handleOpenClick">Open Popup</wd-button>
<wd-popup v-model="showPopup" position="bottom" @after-enter="handlePopupShow" closable>
  <wd-tabs v-model="tab10" ref="tabsRef">
    <wd-tab v-for="item in tabs" :key="item" :title="item" :name="item">
      <view class="content">Content{{ tab10 }}</view>
    </wd-tab>
  </wd-tabs>
</wd-popup>
ts
import type { TabsInstance } from '@/uni_modules/wot-ui/components/wd-tabs/types'

const showPopup = ref(false)
const tabsRef = ref<TabsInstance>()

function handleOpenClick() {
  showPopup.value = true
}

function handlePopupShow() {
  tabsRef.value?.updateLineStyle(false)
}

Tabs Attributes ​

ParameterDescriptionTypeDefault Value
v-modelActive item; explicit names take precedence, falling back to a valid numeric index when no name matchesnumber | string0
slidable-numThreshold for automatically enabling scrollable tabsnumber6
map-numThreshold for showing navigation mapnumber10
map-titleNavigation map titlestring-
stickyWhether to enable sticky layoutbooleanfalse
offset-topSticky offsetnumber0
swipeableWhether to enable gesture swipebooleanfalse
line-themeBottom bar style, optional values are normal, text, underline, dotTabsLineThemenormal
line-widthBottom bar width`numberstring`
line-heightBottom bar height`numberstring`
colorActive item text colorstring''
inactive-colorInactive item text colorstring''
animatedWhether to enable switch animationbooleanfalse
durationAnimation duration, in millisecondsnumber300
slidableWhether to enable scroll navigation, optional values are auto, alwaysTabsSlidableauto
show-scrollbarWhether to show scrollbar when scrollingbooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Tabs Events ​

Event NameDescriptionParameters
changeTriggered when active item changes{ index, name }
clickTriggered when clicking tab title{ index, name }
disabledTriggered when clicking disabled tab{ index, name }
update:modelValueTriggered when active item changes`number

Tabs Methods ​

Method NameDescriptionParametersReturn Value
setActiveSet active item(value: number | string, init: boolean, setScroll: boolean)-
scrollIntoViewScroll selected item into view--
updateLineStyleUpdate active item bottom bar style(animation?: boolean)-

Tabs Slots ​

NameDescription
defaultTab content

Tab Attributes ​

ParameterDescriptionTypeDefault Value
nameTab unique identifier, defaults to index`numberstring`
titleTab titlestring-
disabledWhether disabledbooleanfalse
lazyWhether to lazy load contentbooleantrue
badge-propsBadge properties, passed to Badge componentPartial<BadgeProps>-
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Tab Slots ​

NameDescription
defaultTab content

主题定制 ​

CSS 变量 ​

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置。

名称默认值描述
--wot-tabs-nav-bg$filled-oppo导航背景色
--wot-tabs-nav-sticky-width100vw导航吸顶宽度
--wot-tabs-nav-color$text-secondary导航文字颜色
--wot-tabs-nav-color-active$primary-6导航激活文字颜色
--wot-tabs-nav-font-weight-active$font-weight-medium导航激活文字字重
--wot-tabs-nav-item-font-size$typography-body-size-extra-large导航项字号
--wot-tabs-nav-item-line-height$typography-body-line-height-size-extra-large导航项行高
--wot-tabs-nav-item-padding$padding-main $padding-extra-loose导航项内边距
--wot-tabs-nav-color-disabled$text-disabled导航禁用文字颜色
--wot-tabs-nav-line-bg$primary-6导航线背景色
--wot-tabs-nav-line-height$n-4导航线高度
--wot-tabs-nav-line-width$n-24导航线宽度
--wot-tabs-nav-line-bottom$n-2导航线底部偏移
--wot-tabs-duration0.3s过渡时长
--wot-tabs-map-modal-bg$opac-7_55地图模式遮罩背景
--wot-tabs-map-arrow-size$n-16地图模式箭头尺寸
--wot-tabs-map-arrow-color$icon-secondary地图模式箭头颜色
--wot-tabs-map-btn-width$n-44地图模式按钮宽度
--wot-tabs-map-btn-height$n-44地图模式按钮高度
--wot-tabs-map-btn-before-bglinear-gradient(270deg, $filled-oppo 0%, $base-transparent 100%)地图模式按钮前景渐变背景
--wot-tabs-map-color$text-main地图模式通用文字颜色
--wot-tabs-map-header-font-size$typography-body-size-extra-large地图模式头部字号
--wot-tabs-map-header-line-height$typography-body-line-height-size-extra-large地图模式头部行高
--wot-tabs-map-header-padding$padding-main $padding-extra-loose地图模式头部内边距
--wot-tabs-map-nav-btn-gap$spacing-main地图模式导航按钮间距
--wot-tabs-map-nav-btn-disabled-opacity$opacity-disabled地图模式导航按钮禁用透明度
--wot-tabs-map-nav-btn-bg$filled-bottom地图模式导航按钮背景
--wot-tabs-map-nav-btn-color$text-main地图模式导航按钮文字颜色
--wot-tabs-map-nav-btn-radius$radius-main地图模式导航按钮圆角
--wot-tabs-map-nav-btn-font-size$typography-body-size-ultra-large地图模式导航按钮字号
--wot-tabs-map-nav-btn-line-height$typography-body-line-height-size-ultra-large地图模式导航按钮行高
--wot-tabs-map-nav-btn-padding$padding-tight $padding-extra-loose地图模式导航按钮内边距
--wot-tabs-map-body-padding$padding-loose $padding-extra-loose地图模式内容内边距
--wot-tabs-map-body-bg$filled-oppo地图模式内容背景色

Source Code ​

Documentation
• Component

Released under the MIT License.

Released under the MIT License.