packages/sidebar/README.md
垂直展示的导航栏,用于在不同的内容区域之间进行切换。
在app.json或index.json中引入组件,详细介绍见快速上手。
"usingComponents": {
"van-sidebar": "@vant/weapp/sidebar/index",
"van-sidebar-item": "@vant/weapp/sidebar-item/index"
}
Vant Weapp 1.0 版本开始支持此组件,升级方式参见快速上手
通过在van-sidebar上设置activeKey属性来控制选中项。
<van-sidebar active-key="{{ activeKey }}">
<van-sidebar-item title="标签名" />
<van-sidebar-item title="标签名" />
<van-sidebar-item title="标签名" />
</van-sidebar>
Page({
data: {
activeKey: 0,
},
});
设置dot属性后,会在右上角展示一个小红点。设置badge属性后,会在右上角展示相应的徽标。
<van-sidebar active-key="{{ activeKey }}">
<van-sidebar-item title="标签名" dot />
<van-sidebar-item title="标签名" badge="5" />
<van-sidebar-item title="标签名" badge="99+" />
</van-sidebar>
通过disabled属性禁用选项。
<van-sidebar active-key="{{ activeKey }}">
<van-sidebar-item title="标签名" />
<van-sidebar-item title="标签名" disabled />
<van-sidebar-item title="标签名" />
</van-sidebar>
设置change方法来监听切换导航项时的事件。
<van-sidebar active-key="{{ activeKey }}" bind:change="onChange">
<van-sidebar-item title="标签名 1" />
<van-sidebar-item title="标签名 2" />
<van-sidebar-item title="标签名 3" />
</van-sidebar>
<van-notify id="van-notify" />
import Notify from '@vant/weapp/notify/notify';
Page({
data: {
activeKey: 0,
},
onChange(event) {
Notify({ type: 'primary', message: event.detail });
},
});
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| activeKey | 选中项的索引 | string | number | 0 |
| 事件名 | 说明 | 参数 |
|---|---|---|
| change | 切换徽章时触发 | 当前选中徽章的索引 |
| 类名 | 说明 |
|---|---|
| custom-class | 根节点样式类 |
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| title | 内容 | string | '' |
| dot | 是否显示右上角小红点 | boolean | false |
| info | 图标右上角徽标的内容(已废弃,请使用 badge 属性) | string | number | '' |
badge v1.5.0 | 图标右上角徽标的内容 | string | number | '' |
| disabled | 是否禁用该项 | boolean | false |
| 名称 | 说明 |
|---|---|
| title | 自定义标题栏,如果设置了title属性则不生效 |
| 事件名 | 说明 | 参数 |
|---|---|---|
| click | 点击徽章时触发 | event.detail 为当前徽章的索引 |
| 类名 | 说明 |
|---|---|
| custom-class | 根节点样式类 |