Skip to content

Tabbar - Vant 4

Tabbar

Intro

Used to switch between different pages.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { Tabbar, TabbarItem } from'vant'; const app = createApp(); app.use(Tabbar); app.use(TabbarItem);

Usage

Basic Usage

html
js
import { ref } from'vue'; exportdefault { setup() { const active = ref(0); return { active }; }, };

Match by name

html
js
import { ref } from'vue'; exportdefault { setup() { const active = ref('home'); return { active }; }, };

Show Badge

html

Custom Icon

Use icon slot to custom icon.

html
js
import { ref } from'vue'; exportdefault { setup() { const active = ref(0); const icon = { active: 'https://fastly.jsdelivr.net/npm/@vant/assets/user-active.png', inactive: 'https://fastly.jsdelivr.net/npm/@vant/assets/user-inactive.png', }; return { icon, active, }; }, };

Custom Color

html

Change Event

html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const active = ref(0); constonChange = (index) => showToast(`Tab ${index}`); return { icon, onChange, }; }, };

Route Mode

html

API

Tabbar Props

AttributeDescriptionTypeDefault
v-modelIdentifier of current tab*numberstring*
fixedWhether to fixed bottombooleantrue
borderWhether to show borderbooleantrue
z-indexZ-index*numberstring*
active-colorColor of active tab itemstring#1989fa

| inactive-color | Color of inactive tab item | string | #7d7e80 |

| route | Whether to enable route mode | boolean | false | | placeholder | Whether to generate a placeholder element when fixed | boolean | false | | safe-area-inset-bottom | Whether to enable bottom safe area adaptation | boolean | false | | before-change | Callback function before changing tab, return false to prevent change, support return Promise | (name: number | string) => boolean | Promise<boolean> | - |

Tabbar Events

EventDescriptionArguments
changeEmitted when changing active tab*active: number

TabbarItem Props

AttributeDescriptionTypeDefault
nameIdentifier*numberstring*
iconIcon namestring-
icon-prefixIcon className prefixstringvan-icon
dotWhether to show red dotboolean-
badgeContent of the badge*numberstring*
badge-propsProps of Badge, see Badge - propsBadgeProps-

| url | Link | string | - | | to | The target route should navigate to when clicked on, same as the to prop of Vue Router | string | object | - |

| replace | If true, the navigation will not leave a history record | boolean | false |

TabbarItem Slots

NameDescriptionSlotProps
iconCustom iconactive: boolean

Types

The component exports the following type definitions:

ts
importtype { TabbarProps, TabbarItemProps } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-tabbar-height50px-
--van-tabbar-z-index1-
--van-tabbar-backgroundvar(--van-background-2)-
--van-tabbar-item-font-sizevar(--van-font-size-sm)-
--van-tabbar-item-text-colorvar(--van-text-color)-
--van-tabbar-item-active-colorvar(--van-primary-color)-
--van-tabbar-item-active-backgroundvar(--van-background-2)-
--van-tabbar-item-line-height1-
--van-tabbar-item-icon-size22px-
--van-tabbar-item-icon-margin-bottomvar(--van-padding-base)-

Enterprise-level mobile solution based on Vant