Sidebar
Introduction
A vertically displayed navigation bar for switching between different content areas.
Code Demonstration
Basic usage
Bind the index of the currently selected item through v-model
.
<z-sidebar v-model="active">
<z-sidebar-item title="tag name" />
<z-sidebar-item title="label name" />
<z-sidebar-item title="tag name" />
</z-sidebar>
import { ref } from 'vue';
export default {
setup() {
const active = ref(0);
return { active };
},
};
Disable options
Disable the option with the disabled
attribute.
<z-sidebar v-model="active">
<z-sidebar-item title="tag name" />
<z-sidebar-item title="label name" disabled />
<z-sidebar-item title="label name" />
</z-sidebar>
Listening to Switch Events
Set the change
method to listen for events when switching navigation items.
<z-sidebar v-model="active" @change="onChange">
<z-sidebar-item title="Tag name 1" />
<z-sidebar-item title="label name 2" />
<z-sidebar-item title="Tag name 3" />
</z-sidebar>
import { ref } from 'vue';
import { useToast } from '@/uni_modules/zebra-ui'
const toast = useToast()
export default {
setup() {
const active = ref(0);
const onChange = (index: number) => toast.showToast(`Title ${index + 1}`)
return {
active,
onChange,
};
},
};
Logo tips
After setting the dot
property, a small red dot will be displayed in the upper right corner; After setting the badge
property, the corresponding logo will be displayed in the upper right corner.
<z-sidebar v-model="active">
<z-sidebar-item title="label name" dot />
<z-sidebar-item title="label name" badge="5" />
<z-sidebar-item title="tag name" />
</z-sidebar>
API
Sidebar Props
Parameter | Description | Type | Default Value |
---|---|---|---|
v-model | Index of the current navigation item | number | string | 0 |
Sidebar Events
Event Name | Description | Callback Parameter |
---|---|---|
change | Triggered when switching navigation items | index: number |
SidebarItem Props
Parameter | Description | Type | Default Value |
---|---|---|---|
title | content | string | '' |
dot | Whether to display the small red dot in the upper right corner | boolean | false |
badge | The content of the logo in the upper right corner of the icon | number | string | - |
badge-props | Customize the attributes of the badge. The passed-in object will be passed through to the Badge component props | BadgeProps | - |
disabled | Whether to disable the item | boolean | false |
SidebarItem Events
Event Name | Description | Callback Parameter |
---|---|---|
click | Triggered when clicked | index: number |
SidebarItem Slots
Name | Description |
---|---|
title | Customize Title |
Theme customization
Style Variables
The component provides the following CSS variables that can be used to customize styles. For usage, please refer to the ConfigProvider Component.
Name | Default Value | Description |
---|---|---|
--z-sidebar-width | 160rpx | - |
--z-sidebar-font-size | var(--z-font-size-md) | - |
--z-sidebar-line-height | var(--z-line-height-md) | - |
--z-sidebar-text-color | var(--z-text-color) | - |
--z-sidebar-disabled-text-color | var(--z-text-color-3) | - |
--z-sidebar-padding | 40rpx var(--z-padding-sm) | - |
--z-sidebar-active-color | var(--z-active-color) | - |
--z-sidebar-background | var(--z-background) | - |
--z-sidebar-selected-font-weight | var(--z-font-bold) | - |
--z-sidebar-selected-text-color | var(--z-text-color) | - |
--z-sidebar-selected-border-width | 8rpx | - |
--z-sidebar-selected-border-height | 32rpx | - |
--z-sidebar-selected-border-color | var(--z-primary-color) | - |
--z-sidebar-selected-background | var(--z-background-2) | - |