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

Sidebar

Intro

The vertically displayed navigation bar is used to switch between different content areas.

Install

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

import { createApp } from 'vue';
import { Sidebar, SidebarItem } from 'vant';

const app = createApp();
app.use(Sidebar);
app.use(SidebarItem);

Usage

Basic Usage

<van-sidebar v-model="active">
  <van-sidebar-item title="Title" />
  <van-sidebar-item title="Title" />
  <van-sidebar-item title="Title" />
</van-sidebar>
import { ref } from 'vue';

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

Show Badge

<van-sidebar v-model="active">
  <van-sidebar-item title="Title" dot />
  <van-sidebar-item title="Title" badge="5" />
  <van-sidebar-item title="Title" badge="20" />
</van-sidebar>

Disabled

<van-sidebar v-model="active">
  <van-sidebar-item title="Title" />
  <van-sidebar-item title="Title" disabled />
  <van-sidebar-item title="Title" />
</van-sidebar>

Change Event

<van-sidebar v-model="active" @change="onChange">
  <van-sidebar-item title="Title 1" />
  <van-sidebar-item title="Title 2" />
  <van-sidebar-item title="Title 3" />
</van-sidebar>
import { ref } from 'vue';
import { Toast } from 'vant';

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

API

AttributeDescriptionTypeDefault
v-modelIndex of chosen itemnumber | string0
EventDescriptionArguments
changeEmitted when chosen item changedindex: number

SidebarItem Props

AttributeDescriptionTypeDefault
titleContentstring''
dotWhether to show red dotbooleanfalse
badgeContent of the badgenumber | string''
badge-props v3.2.8Props of Badge, see Badge - propsBadgeProps-
disabledWhether to be disabledbooleanfalse
urlLinkstring-
toTarget route of the link, same as to of vue-routerstring | object-
replaceIf true, the navigation will not leave a history recordbooleanfalse

SidebarItem Events

EventDescriptionArguments
clickEmitted when an item is clickedindex: number

SidebarItem Slots

NameDescription
titleCustom item title

Types

The component exports the following type definitions:

import type { 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-background-colorvar(--van-background-color)-
--van-sidebar-selected-font-weightvar(--van-font-weight-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-danger-color)-
--van-sidebar-selected-background-colorvar(--van-background-color-light)-
`,17),l=[d],h={__name:"README",setup(r,{expose:s}){return s({frontmatter:{}}),(c,i)=>(a(),t("div",e,l))}};export{h as default};