Skip to content

Sidebar 侧边栏

查看 sn-sidebar 的 2.0 版本差异

基础用法

  • 侧边导航栏,适用于商城选购等场景
  • 左侧为选项列表(v-model 控制选中索引),右侧为内容区(default 插槽)
  • 支持锚点定位(anchor)与选中线(showLine)
vue
<template>
	<sn-sidebar v-model="index" :data="items">
		<view>右侧内容区</view>
	</sn-sidebar>
</template>

更多演示请下载 demo 查看

锚点定位

anchor 为 true 时,选中项变化会驱动内容区滚动到对应 id 的节点(scroll-into-view),需在内容区放置带相同 id 的节点。

vue
<template>
	<sn-sidebar v-model="index" :data="items" anchor>
		<scroll-view>
			<view :id="items[0].id">模块一</view>
			<view :id="items[1].id">模块二</view>
		</scroll-view>
	</sn-sidebar>
</template>

外部样式

bar-class / bar-style 定制左侧侧边栏,item-class / item-style 定制选项,content-class / content-style 定制内容区。

属性

参数说明类型默认值可选值
v-model当前选中的选项索引Number0-
data侧边栏选项数据数组Array<SnDataItem>[]-
width侧边栏宽度String'100px'-
itemWidth选项宽度String'100px'-
itemPadding选项内边距(支持 1~4 值简写)String'15px 0'-
itemTextColor选项文字颜色,为空时取主题 $textString''-
itemTextSize选项文字大小,为空时 16 × fontsizeFactorString | Number''-
activeItemTextColor选中选项文字颜色,为空时取主题 $primaryString''-
itemBgColor选项背景颜色,为空时透明String''-
itemBorderRadius选项圆角大小String | Number'0'-
activeItemBgColor选中选项背景颜色,为空时取主题 $frontString''-
disabled是否禁用所有选项Booleanfalsetrue | false
anchor是否使用锚点定位,选中时内容区滚动到对应 idBooleanfalsetrue | false
showLine是否显示选中线Booleantruetrue | false
lineColor选中线颜色,为空时取主题 $primaryString''-
customStyle自定义容器样式UTSJSONObject | String''-
itemStyle自定义选项样式UTSJSONObject | String''-
itemClass选项外部样式类String''-
barStyle自定义侧边栏(左侧列表)样式UTSJSONObject | String''-
barClass侧边栏外部样式类String''-
contentStyle自定义内容区样式UTSJSONObject | String''-
contentClass内容区外部样式类String''-

通用数据项类型,全局弹窗操作菜单与多数列表类组件共用(组件侧详见组件类型)。

字段类型必备描述
idString项 id
textString显示文本
iconString图标名
valueString关联值
colorString文本颜色
disabledBoolean是否禁用

事件

名称类型说明
change(value: number) => Void选项改变时触发

插槽

名称说明
default放置侧边栏右侧的内容区域

使用 MIT 协议