# Sidebar A vertical navigation bar used to switch between different content areas. ## Basic Usage Bind the current selected item's index through `v-model`. ```html ``` ```typescript const active = ref(0) ``` ## Badge Tips After setting the `is-dot` property, a small red dot will be displayed in the upper right corner. Setting the `badge` property will display the corresponding badge in the upper right corner. ```html ``` ## Disabled Options Disable options through the `disabled` property. ```html ``` ## Listen to Switch Events Set the `change` method to listen to events when switching navigation items. ```html ``` ```typescript import { useToast } from '@/uni_modules/wot-design-uni' const toast = useToast() const active = ref(1) function handleChange({ value, label }) { toast.show(`Current Label Name ${label}`) } ``` ## Asynchronous Switching Through the `before-change` property, you can execute specific logic before switching tabs. It receives `{ value, resolve }` parameters, continues execution through `resolve`, and `resolve` accepts 1 boolean parameter. ```html ``` ```typescript import { useToast } from '@/uni_modules/wot-design-uni' import type { SidebarBeforeChange } from '@/uni_modules/wot-design-uni/components/wd-sidebar/types' import { ref } from 'vue' const { loading: showLoading, close: closeLoading } = useToast() const toast = useToast() const active = ref(1) const beforeChange: SidebarBeforeChange = ({ value, resolve }) => { showLoading('Switching') setTimeout(() => { closeLoading() resolve(true) }, 2000) } ``` ## Anchor Usage Example The anchor usage of the sidebar component can help users quickly navigate to specific sections on long pages. ::: details View Anchor Usage Example ::: code-group ```html [vue] ``` ```typescript [typescript] ``` ```css [css] .wraper { display: flex; height: 100vh; overflow: hidden; } .content { flex: 1; height: 100%; } .category { background: #fff; } ``` ::: ## Attributes | Parameter | Description | Type | Accepted Values | Default | Version | |-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|-----------------|---------|---------| | modelValue/v-model | Index of current navigation item | string / number | - | 0 | 0.1.49 | | before-change | Hook before switching navigation items. Can execute specific logic before switching tabs. Receives { value, resolve } parameters, continue execution through resolve | function | - | - | 1.4.0 | ## Events | Event Name | Description | Parameters | Version | |------------|--------------------------------|---------------------------------------------|---------| | change | Triggered when option switches | `(value: number \| string, label: string)` | 0.1.49 | ## Slots | Name | Description | Parameters | Version | |---------|----------------|------------|---------| | default | Custom display | - | 0.1.49 | ## External Classes | Class Name | Description | Version | |-------------|------------------|----------| | customStyle | Custom style | 0.1.49 | | customClass | Custom style class| 0.1.49 | ## SidebarItem Attributes | Parameter | Description | Type | Accepted Values | Default | Version | |-------------|----------------------------------------------------------------------------------------------------------------|---------------------------|-----------------|---------|---------| | label | Current option title | string | - | - | 0.1.49 | | value | Current option value, unique identifier | `number / string` | - | - | 0.1.49 | | icon | Icon | string | - | - | 0.1.49 | | badge | Badge value | `number / string / null` | - | - | 0.1.49 | | isDot | Whether to display dot badge | boolean | - | false | 0.1.49 | | max | Maximum badge value | number | - | 99 | 0.1.49 | | disabled | Whether disabled | boolean | - | false | 0.1.49 | | badge-props | Custom badge properties, passed object will be transparent to [Badge component props](/component/badge#attributes)| BadgeProps | - | - | 0.1.50 | ## SidebarItem Slots | Name | Description | Parameters | Version | |------|----------------|------------|---------| | icon | Custom icon | - | 0.1.49 | ## SidebarItem External Classes | Class Name | Description | Version | |-------------|------------------|----------| | customStyle | Custom style | 0.1.49 | | customClass | Custom style class| 0.1.49 |