import{o as a,a as t,y as n}from"./vue-libs.b44bc779.js";const l={class:"van-doc-markdown-body"},e=n(`

Tabbar

Intro

Used to switch between different pages.

Install

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

import { createApp } from 'vue';
import { Tabbar, TabbarItem } from 'vant';

const app = createApp();
app.use(Tabbar);
app.use(TabbarItem);

Usage

Basic Usage

<van-tabbar v-model="active">
  <van-tabbar-item icon="home-o">Tab</van-tabbar-item>
  <van-tabbar-item icon="search">Tab</van-tabbar-item>
  <van-tabbar-item icon="friends-o">Tab</van-tabbar-item>
  <van-tabbar-item icon="setting-o">Tab</van-tabbar-item>
</van-tabbar>
import { ref } from 'vue';

export default {
  setup() {
    const active = ref(0);
    return { active };
  },
};

Match by name

<van-tabbar v-model="active">
  <van-tabbar-item name="home" icon="home-o">Tab</van-tabbar-item>
  <van-tabbar-item name="search" icon="search">Tab</van-tabbar-item>
  <van-tabbar-item name="friends" icon="friends-o">Tab</van-tabbar-item>
  <van-tabbar-item name="setting" icon="setting-o">Tab</van-tabbar-item>
</van-tabbar>
import { ref } from 'vue';

export default {
  setup() {
    const active = ref('home');
    return { active };
  },
};

Show Badge

<van-tabbar v-model="active">
  <van-tabbar-item icon="home-o">Tab</van-tabbar-item>
  <van-tabbar-item icon="search" dot>Tab</van-tabbar-item>
  <van-tabbar-item icon="friends-o" badge="5">Tab</van-tabbar-item>
  <van-tabbar-item icon="setting-o" badge="20">Tab</van-tabbar-item>
</van-tabbar>

Custom Icon

Use icon slot to custom icon.

<van-tabbar v-model="active">
  <van-tabbar-item badge="3">
    <span>Custom</span>
    <template #icon="props">
      <img :src="props.active ? icon.active : icon.inactive" />
    </template>
  </van-tabbar-item>
  <van-tabbar-item icon="search">Tab</van-tabbar-item>
  <van-tabbar-item icon="setting-o">Tab</van-tabbar-item>
</van-tabbar>
import { ref } from 'vue';

export default {
  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

<van-tabbar v-model="active" active-color="#ee0a24" inactive-color="#000">
  <van-tabbar-item icon="home-o">Tab</van-tabbar-item>
  <van-tabbar-item icon="search">Tab</van-tabbar-item>
  <van-tabbar-item icon="friends-o">Tab</van-tabbar-item>
  <van-tabbar-item icon="setting-o">Tab</van-tabbar-item>
</van-tabbar>

Change Event

<van-tabbar v-model="active" @change="onChange">
  <van-tabbar-item icon="home-o">Tab 1</van-tabbar-item>
  <van-tabbar-item icon="search">Tab 2</van-tabbar-item>
  <van-tabbar-item icon="friends-o">Tab 3</van-tabbar-item>
  <van-tabbar-item icon="setting-o">Tab 4</van-tabbar-item>
</van-tabbar>
import { ref } from 'vue';
import { Toast } from 'vant';

export default {
  setup() {
    const active = ref(0);
    const onChange = (index) => Toast(\`Tab \${index}\`);
    return {
      icon,
      onChange,
    };
  },
};

Route Mode

<router-view />

<van-tabbar route>
  <van-tabbar-item replace to="/home" icon="home-o">Tab</van-tabbar-item>
  <van-tabbar-item replace to="/search" icon="search">Tab</van-tabbar-item>
</van-tabbar>

API

Tabbar Props

AttributeDescriptionTypeDefault
v-modelIdentifier of current tabnumber | string0
fixedWhether to fixed bottombooleantrue
borderWhether to show borderbooleantrue
z-indexZ-indexnumber | string1
active-colorColor of active tab itemstring#1989fa
inactive-colorColor of inactive tab itemstring#7d7e80
routeWhether to enable route modebooleanfalse
placeholderWhether to generate a placeholder element when fixedbooleanfalse
safe-area-inset-bottomWhether to enable bottom safe area adaptationbooleanfalse
before-changeCallback 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 tabactive: number | string

TabbarItem Props

AttributeDescriptionTypeDefault
nameIdentifiernumber | stringItem index
iconIcon namestring-
icon-prefixIcon className prefixstringvan-icon
dotWhether to show red dotboolean-
badgeContent of the badgenumber | string''
badge-props v3.2.8Props of Badge, see Badge - propsBadgeProps-
urlLinkstring-
toTarget route of the link, same as to of vue-routerstring | object-
replaceIf true, the navigation will not leave a history recordbooleanfalse

TabbarItem Slots

NameDescriptionSlotProps
iconCustom iconactive: boolean

Types

The component exports the following type definitions:

import type { 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-background-colorvar(--van-background-color-light)-
--van-tabbar-item-font-sizevar(--van-font-size-sm)-
--van-tabbar-item-text-colorvar(--van-gray-7)-
--van-tabbar-item-active-colorvar(--van-primary-color)-
--van-tabbar-item-active-background-colorvar(--van-background-color-light)-
--van-tabbar-item-line-height1-
--van-tabbar-item-icon-size22px-
--van-tabbar-item-icon-margin-bottomvar(--van-padding-base)-
`,19),p=[e],i={__name:"README",setup(c,{expose:s}){return s({frontmatter:{}}),(o,d)=>(a(),t("div",l,p))}};export{i as default};