Skip to content

Tabbar

Bottom navigation bar for switching between different pages.

Component Types

Basic Usage

v-model is the bound value, representing the index or name of the selected tab.

html
<wd-tabbar v-model="tabbar">
  <wd-tabbar-item title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item title="Category" icon="cart"></wd-tabbar-item>
  <wd-tabbar-item title="My" icon="user"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

Match by Name

By setting the name property, you can match the selected tab by name.

html
<wd-tabbar v-model="tabbar">
  <wd-tabbar-item name="home" title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item name="cart" title="Category" icon="cart"></wd-tabbar-item>
  <wd-tabbar-item name="setting" title="Settings" icon="setting"></wd-tabbar-item>
  <wd-tabbar-item name="user" title="My" icon="user"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref('home')

Component States

Badge Tips

By setting the value property, you can display badge tips. Setting the is-dot property will display a small red dot in the upper right corner of the icon.

html
<wd-tabbar v-model="tabbar">
  <wd-tabbar-item is-dot :value="2" title="Dot" icon="home"></wd-tabbar-item>
  <wd-tabbar-item :value="2" icon="cart" title="Category"></wd-tabbar-item>
  <wd-tabbar-item :value="30" title="My" icon="user"></wd-tabbar-item>
  <wd-tabbar-item :value="200" title="Max Value" icon="user"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

Component Variants

Floating Tabbar

By setting the shape property to round, you can set the tabbar to a floating style.

html
<wd-tabbar shape="round" v-model="tabbar">
  <wd-tabbar-item title="Home" is-dot :value="2" icon="home"></wd-tabbar-item>
  <wd-tabbar-item title="Category" :value="2" icon="cart"></wd-tabbar-item>
  <wd-tabbar-item title="Album" :value="30" icon="photo"></wd-tabbar-item>
  <wd-tabbar-item title="My" :value="200" icon="user"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

Component Styles

Custom Icon

You can customize the tab icon by using <template #icon>.

html
<wd-tabbar v-model="tabbar">
  <wd-tabbar-item :value="2" title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item :value="2" icon="cart" title="Category">
    <template #icon>
      <wd-img round height="40rpx" width="40rpx" src="https://wot-ui.cn/assets/panda.jpg"></wd-img>
    </template>
  </wd-tabbar-item>
  <wd-tabbar-item :value="3" title="My" icon="user"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

Custom Color

By setting active-color and inactive-color properties, you can customize the colors for active and inactive tabs.

html
<wd-tabbar v-model="tabbar" active-color="#ee0a24" inactive-color="#7d7e80">
  <wd-tabbar-item is-dot :value="2" title="Dot" icon="home"></wd-tabbar-item>
  <wd-tabbar-item :value="2" icon="cart" title="Category"></wd-tabbar-item>
  <wd-tabbar-item :value="30" title="My" icon="user"></wd-tabbar-item>
  <wd-tabbar-item :value="200" title="Max Value" icon="photo"></wd-tabbar-item>
  <wd-tabbar-item :value="10" title="Service" icon="chat"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

Special Styles

Listen to Switch Events

By listening to the change event, you can get the value of the selected tab.

html
<wd-tabbar v-model="tabbar" @change="handleChange" active-color="#ee0a24" inactive-color="#7d7e80">
  <wd-tabbar-item title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item title="Category" icon="cart"></wd-tabbar-item>
  <wd-tabbar-item title="My" icon="user"></wd-tabbar-item>
  <wd-tabbar-item title="Album" icon="photo"></wd-tabbar-item>
  <wd-tabbar-item title="Service" icon="chat"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

function handleChange({ value }: { value: string }) {
  show(`Selected tab:${value}`)
}

Default Slot

You can customize special content like middle buttons through the default slot of wd-tabbar-item.

html
<wd-tabbar v-model="tabbar" safeAreaInsetBottom placeholder>
  <wd-tabbar-item title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item title="Category" icon="store"></wd-tabbar-item>
  <wd-tabbar-item>
    <view class="custom-raised-button">
      <wd-icon name="plus" size="32px"></wd-icon>
    </view>
  </wd-tabbar-item>
  <wd-tabbar-item title="Album" icon="image"></wd-tabbar-item>
  <wd-tabbar-item title="Service" icon="message"></wd-tabbar-item>
</wd-tabbar>

Before Change Interception

Through before-change, you can do synchronous or asynchronous confirmation before switching.

html
<wd-tabbar v-model="tabbar" :before-change="beforeChange">
  <wd-tabbar-item title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item title="Category" icon="store"></wd-tabbar-item>
</wd-tabbar>
ts
function beforeChange(value) {
  return Promise.resolve(true)
}

Fixed Bottom

By setting the fixed property, you can fix the tabbar at the bottom. By setting the placeholder property, you can generate an equal-height placeholder element at the tab position when fixed at the bottom.

html
<wd-tabbar fixed v-model="tabbar" bordered safeAreaInsetBottom placeholder>
  <wd-tabbar-item :value="2" is-dot title="Home" icon="home"></wd-tabbar-item>
  <wd-tabbar-item title="Category" icon="cart"></wd-tabbar-item>
  <wd-tabbar-item title="My" icon="user"></wd-tabbar-item>
  <wd-tabbar-item :value="200" title="Album" icon="photo"></wd-tabbar-item>
  <wd-tabbar-item :value="10" title="Service" icon="chat"></wd-tabbar-item>
</wd-tabbar>
ts
import { ref } from 'vue'

const tabbar = ref(1)

Tabbar Attributes

ParameterDescriptionTypeDefault Value
model-value / v-modelIndex or name of the selected tabnumber | string0
fixedWhether to fix at the bottombooleanfalse
borderedWhether to show top borderbooleanfalse
safe-area-inset-bottomWhether to set bottom safe areabooleanfalse
shapeTabbar shape, optional values are default, roundTabbarShape'default'
active-colorActive tab colorstring-
inactive-colorInactive tab colorstring-
placeholderWhen fixed at the bottom, whether to generate an equal-height placeholder elementbooleanfalse
z-indexComponent z-index levelnumber10
before-changeCallback function before switching, returning false can prevent switching, supports returning Promise<boolean>TabbarBeforeChange-
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Events

Event NameDescriptionParameters
changeTriggered when tab switches{ value }

Tabbar Slots

nameDescription
defaultTabbarItem list

Tabbar External Style Classes

Class NameDescription
custom-classRoot node style class
custom-styleRoot node style

TabbarItem Attributes

ParameterDescriptionTypeDefault Value
titleTab titlestring-
nameUnique identifier, defaults to index value if not passedstring | number-
iconIcon namestring-
valueBadge display valuenumber | string-
is-dotWhether to show dot badgebooleanfalse
maxBadge maximum valuenumber99
badge-props v0.1.50Custom badge properties, passed to Badge componentBadgeProps-
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

TabbarItem Slots

nameDescriptionParameters
defaultCustomize the entire tab item content-
iconCustom icon{ active }

主题定制

CSS 变量

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

名称默认值描述
--wot-tabbar-height$n-50高度
--wot-tabbar-bg$filled-oppo背景色
--wot-tabbar-z-index10固定定位层级
--wot-tabbar-round-margin-horizontal$spacing-extra-looseround 变体水平外边距
--wot-tabbar-round-radius$radius-radius-fullround 变体圆角

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.