Skip to content

Sidebar - Vant 4

Install

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

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

Usage

Basic Usage

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

Show Badge

html

Disabled

html

Change Event

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

API

AttributeDescriptionTypeDefault
v-modelIndex of chosen item*numberstring*
EventDescriptionArguments
changeEmitted when chosen item changedindex: number

SidebarItem Props

AttributeDescriptionTypeDefault
titleContentstring''
dotWhether to show red dotbooleanfalse
badgeContent of the badge*numberstring*
badge-propsProps of Badge, see Badge - propsBadgeProps-

| disabled | Whether to be disabled | boolean | false | | 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 |

SidebarItem Events

EventDescriptionArguments
clickEmitted when an item is clickedindex: number

SidebarItem Slots

NameDescription
titleCustom item title

Types

The component exports the following type definitions:

ts
importtype { SidebarProps, SidebarItemProps } 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-sidebar-width80px-
--van-sidebar-font-sizevar(--van-font-size-md)-
--van-sidebar-line-heightvar(--van-line-height-md)-
--van-sidebar-text-colorvar(--van-text-color)-
--van-sidebar-disabled-text-colorvar(--van-text-color-3)-
--van-sidebar-padding20px var(--van-padding-sm)-
--van-sidebar-active-colorvar(--van-active-color)-
--van-sidebar-backgroundvar(--van-background)-
--van-sidebar-selected-font-weightvar(--van-font-bold)-
--van-sidebar-selected-text-colorvar(--van-text-color)-
--van-sidebar-selected-border-width4px-
--van-sidebar-selected-border-height16px-
--van-sidebar-selected-border-colorvar(--van-primary-color)-
--van-sidebar-selected-backgroundvar(--van-background-2)-

Enterprise-level mobile solution based on Vant