# Tabbar
### Intro
Used to switch between different pages.
### Install
Register component globally via `app.use`, refer to [Component Registration](#/en-US/advanced-usage#zu-jian-zhu-ce) 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
Tab
Tab
Tab
Tab
```
```js
import { ref } from 'vue';
export default {
setup() {
const active = ref(0);
return { active };
},
};
```
### Match by name
```html
Tab
Tab
Tab
Tab
```
```js
import { ref } from 'vue';
export default {
setup() {
const active = ref('home');
return { active };
},
};
```
### Show Badge
```html
Tab
Tab
Tab
Tab
```
### Custom Icon
Use `icon` slot to custom icon.
```html
Custom
Tab
Tab
```
```js
import { ref } from 'vue';
export default {
setup() {
const active = ref(0);
const icon = {
active: 'https://img.yzcdn.cn/vant/user-active.png',
inactive: 'https://img.yzcdn.cn/vant/user-inactive.png',
};
return {
icon,
active,
};
},
};
```
### Custom Color
```html
Tab
Tab
Tab
Tab
```
### Change Event
```html
Tab 1
Tab 2
Tab 3
Tab 4
```
```js
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
```html
Tab
Tab
```
## API
### Tabbar Props
| Attribute | Description | Type | Default |
| --- | --- | --- | --- |
| v-model | Identifier of current tab | _number \| string_ | `0` |
| fixed | Whether to fixed bottom | _boolean_ | `true` |
| border | Whether to show border | _boolean_ | `true` |
| z-index | Z-index | _number \| string_ | `1` |
| active-color | Color of active tab item | _string_ | `#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\_ | - |
### Tabbar Events
| Event | Description | Arguments |
| ------ | -------------------------------- | -------------------------- |
| change | Emitted when changing active tab | _active: number \| string_ |
### TabbarItem Props
| Attribute | Description | Type | Default |
| --- | --- | --- | --- |
| name | Identifier | _number \| string_ | Item index |
| icon | Icon name | _string_ | - |
| icon-prefix | Icon className prefix | _string_ | `van-icon` |
| dot | Whether to show red dot | _boolean_ | - |
| badge | Content of the badge | _number \| string_ | `''` |
| url | Link | _string_ | - |
| to | Target route of the link, same as to of vue-router | _string \| object_ | - |
| replace | If true, the navigation will not leave a history record | _boolean_ | `false` |
### TabbarItem Slots
| Name | Description | SlotProps |
| ---- | ----------- | ----------------- |
| icon | Custom icon | _active: boolean_ |
### CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to [ConfigProvider component](#/en-US/config-provider).
| Name | Default Value | Description |
| --- | --- | --- |
| --van-tabbar-height | _50px_ | - |
| --van-tabbar-z-index | _1_ | - |
| --van-tabbar-background-color | _var(--van-white)_ | - |
| --van-tabbar-item-font-size | _var(--van-font-size-sm)_ | - |
| --van-tabbar-item-text-color | _var(--van-gray-7)_ | - |
| --van-tabbar-item-active-color | _var(--van-primary-color)_ | - |
| --van-tabbar-item-active-background-color | _var(--van-white)_ | - |
| --van-tabbar-item-line-height | _1_ | - |
| --van-tabbar-item-icon-size | _22px_ | - |
| --van-tabbar-item-margin-bottom | _4px_ | - |