v-sidebar
介绍
垂直展示的导航栏,用于在不同的内容区域之间进行切换。
预览

引入
方式请参考组件用法 。
代码演示
基础用法
js
<v-sidebar v-model="active">
<v-sidebar-item text="标签名称1" :config="sidebarItemConfig"/>
<v-sidebar-item text="标签名称2" :config="sidebarItemConfig"/>
<v-sidebar-item text="标签名称3" :config="sidebarItemConfig"/>
</v-sidebar>js
export default {
setup() {
const active= ref(3);
const sidebarItemConfig = {
width: 120,
height: 80,
name: 'focusable',
class: 'sidebar-item',
fill: '#fff',
focusFill: '#000', // 落焦字体颜色
activeFill: '#F66239', // 激活字体颜色
focusBackground: '', // 落焦背景颜色
activeBackground: '#0f0', // 激活背景颜色
focusStyle: 'normal ', // 落焦字体样式
activeStyle: 'bold' // 激活字体样式
};
return { sidebarItemConfig, active};
},
};监听切换事件
设置 change 方法来监听切换导航项时的事件。
js
<v-sidebar v-model="active" @change="onChange">
<v-sidebar-item text="标签名称" :config="sidebarItemConfig"/>
<v-sidebar-item text="标签名称" :config="sidebarItemConfig"/>
<v-sidebar-item text="标签名称" :config="sidebarItemConfig"/>
</v-sidebar>js
export default {
setup() {
const active= ref(3);
const onChange = (index) => {
console.log(`标签名 ${index + 1}`)
}
const sidebarItemConfig = {
width: 120,
height: 80,
name: 'focusable',
class: 'sidebar-item',
fill: '#fff',
focusFill: '#000', // 落焦字体颜色
activeFill: '#F66239', // 激活字体颜色
focusBackground: '', // 落焦背景颜色
activeBackground: '#0f0', // 激活背景颜色
focusStyle: 'normal ', // 落焦字体样式
activeStyle: 'bold' // 激活字体样式
};
return {
active,
onChange,
sidebarItemConfig
};
},
};API
Sidebar Props)
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| active | 当前导航项的索引 | number | 0 |
| config | 支持全部v-group属性 | object | -- |
Sidebar Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| change | 切换导航项时触发 | index: number |
SidebarItem Props)
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| text | 内容 | number | string |
| config | 支持全部v-rect属性 | object | -- |
| L fill | 默认字体颜色 | string | #000000 |
| L focusFill | 落焦字体颜色 | string | #FFFFFF |
| L activeFill | 激活字体颜色 | string | #F66239 |
| L focusBackground | 落焦背景颜色 | string | #000000 |
| L activeBackground | 激活背景颜色 | string | #F5A28E |
| L focusStyle | 落焦字体样式 | normal bold italic | normal |
| L activeStyle | 激活字体样式 | normal bold italic | bold |