更新记录
1.0.0(2025-12-24)
下载此版本
新增
- 初始版本发布
- 支持简单模式(items)和分组模式(sections)两种数据结构
- 支持亮色(light)、暗色(dark)、自动(auto)三种主题模式
- 支持无限层级子菜单嵌套
- 支持手风琴模式,同级菜单只展开一个
- 支持分组可折叠功能
- 支持自定义颜色配置(背景色、文字色、选中色、悬浮色等)
- 支持 Logo 标题和副标题显示
- 支持导航项图标(图片路径、base64、文字/emoji)
- 支持导航项角标(badge)
- 支持导航项禁用状态
- 支持分割线和分组标题类型
- 提供 header、footer、section-header、icon、item、badge 六个插槽
- 提供 expandAll、collapseAll 两个公开方法
- 提供 change、item-click、expand、section-expand 事件
- 支持 v-model 双向绑定当前选中项
- 支持默认展开指定菜单项(defaultExpandedIds)
- 自动跟随系统主题切换(H5/App/小程序)
平台兼容性
uni-app(3.6.16)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| √ |
√ |
√ |
√ |
- |
- |
- |
- |
- |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
| √ |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
tri-quicken-side-nav
一个功能丰富的 uni-app 侧边导航栏组件,支持多级菜单、分组模式、主题切换等特性。
特性
- 支持亮色/暗色/自动主题切换
- 支持简单模式和分组模式两种数据结构
- 支持无限层级子菜单
- 支持手风琴模式(同级只展开一个)
- 支持分组可折叠
- 丰富的自定义样式选项
- 提供多个插槽满足自定义需求
安装
从 uni-app 插件市场导入即可使用。
基本用法
简单模式
<template>
<tri-quicken-side-nav
v-model="activeId"
:items="navItems"
@change="handleChange"
/>
</template>
<script>
export default {
data() {
return {
activeId: 'home',
navItems: [
{ id: 'home', label: '首页', icon: '🏠' },
{ id: 'user', label: '用户管理', icon: '👤' },
{ id: 'settings', label: '设置', icon: '⚙️' }
]
}
},
methods: {
handleChange(item) {
console.log('选中:', item)
}
}
}
</script>
分组模式
<template>
<tri-quicken-side-nav
v-model="activeId"
:sections="sections"
/>
</template>
<script>
export default {
data() {
return {
activeId: 'dashboard',
sections: [
{
id: 'main',
title: '主菜单',
items: [
{ id: 'dashboard', label: '仪表盘', icon: '📊' },
{ id: 'analytics', label: '数据分析', icon: '📈' }
]
},
{
id: 'system',
title: '系统设置',
collapsible: true,
defaultExpanded: true,
items: [
{ id: 'profile', label: '个人信息', icon: '👤' },
{ id: 'security', label: '安全设置', icon: '🔒' }
]
}
]
}
}
}
</script>
多级子菜单
<script>
export default {
data() {
return {
navItems: [
{
id: 'products',
label: '产品管理',
icon: '📦',
children: [
{ id: 'product-list', label: '产品列表' },
{ id: 'product-add', label: '添加产品' },
{
id: 'product-category',
label: '产品分类',
children: [
{ id: 'category-1', label: '分类一' },
{ id: 'category-2', label: '分类二' }
]
}
]
}
]
}
}
}
</script>
Props 属性
| 属性名 |
类型 |
默认值 |
说明 |
| v-model / modelValue |
String / Number |
'' |
当前选中项的 ID |
| theme |
String |
'auto' |
主题预设,可选值:'light'、'dark'、'auto' |
| items |
Array |
[] |
简单模式导航数据 |
| sections |
Array |
[] |
分组模式导航数据(优先级高于 items) |
| width |
String |
'280rpx' |
导航栏宽度 |
| backgroundColor |
String |
'' |
背景色(覆盖主题默认值) |
| activeColor |
String |
'' |
选中项背景色(覆盖主题默认值) |
| textColor |
String |
'' |
文字颜色(覆盖主题默认值) |
| hoverColor |
String |
'' |
悬浮态颜色(覆盖主题默认值) |
| logoTitle |
String |
'' |
Logo 主标题文字 |
| logoSubtitle |
String |
'' |
Logo 副标题文字 |
| logoColor |
String |
'' |
Logo 主标题颜色(覆盖主题默认值) |
| subtitleColor |
String |
'' |
Logo 副标题颜色(覆盖主题默认值) |
| sectionTitleColor |
String |
'' |
分组标题颜色(覆盖主题默认值) |
| indent |
Number |
24 |
子级菜单缩进量(单位:rpx) |
| accordion |
Boolean |
false |
是否开启手风琴模式(同级只展开一个) |
| showHeader |
Boolean |
true |
是否显示头部区域 |
| defaultExpandedIds |
Array |
[] |
默认展开的菜单项 ID 数组 |
| iconMap |
Object |
{} |
图标映射表,key 为图标名称,value 为图片路径 |
Events 事件
| 事件名 |
参数 |
说明 |
| update:modelValue |
(id) |
选中项变化时触发,用于 v-model |
| change |
(item) |
选中项变化时触发,返回完整的 item 对象 |
| item-click |
(item) |
点击任意导航项时触发(包括禁用项和有子菜单的项) |
| expand |
(item, expanded) |
菜单项展开/折叠时触发 |
| section-expand |
(section, expanded) |
分组展开/折叠时触发 |
Slots 插槽
| 插槽名 |
插槽参数 |
说明 |
| header |
- |
自定义头部区域内容 |
| footer |
- |
自定义底部区域内容 |
| section-header |
{ section } |
自定义分组标题内容 |
| icon |
{ item, active } |
自定义导航项图标 |
| item |
{ item, active, level } |
自定义导航项整体内容 |
| badge |
{ item } |
自定义角标内容 |
Methods 方法
通过 ref 调用组件方法:
<template>
<tri-quicken-side-nav ref="navRef" :items="items" />
<button @click="$refs.navRef.expandAll()">展开全部</button>
<button @click="$refs.navRef.collapseAll()">折叠全部</button>
</template>
| 方法名 |
参数 |
说明 |
| expandAll |
- |
展开所有可展开的菜单项和分组 |
| collapseAll |
- |
折叠所有菜单项和分组 |
数据结构
Item 导航项
| 字段 |
类型 |
必填 |
说明 |
| id |
String / Number |
是 |
唯一标识 |
| label |
String |
是 |
显示文字 |
| icon |
String |
否 |
图标(支持图片路径、base64、文字/emoji,或 iconMap 中的 key) |
| badge |
String / Number |
否 |
角标内容 |
| disabled |
Boolean |
否 |
是否禁用 |
| type |
String |
否 |
特殊类型:'divider'(分割线)、'header'(分组标题) |
| children |
Array |
否 |
子菜单项数组 |
Section 分组
| 字段 |
类型 |
必填 |
说明 |
| id |
String / Number |
是 |
唯一标识 |
| title |
String |
否 |
分组标题 |
| collapsible |
Boolean |
否 |
是否可折叠 |
| defaultExpanded |
Boolean |
否 |
是否默认展开(仅 collapsible 为 true 时有效) |
| items |
Array |
是 |
分组内的导航项数组 |
主题配置
组件内置两套主题预设:
暗色主题 (dark)
- 背景色:
#1a1a1a
- 文字颜色:
#ffffff
- 选中色:
linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%)
亮色主题 (light)
- 背景色:
#ffffff
- 文字颜色:
#1a1a1a
- 选中色:
linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%)
设置 theme="auto" 时,组件会自动跟随系统主题切换。
使用示例
自定义图标插槽
<template>
<tri-quicken-side-nav :items="items">
<template #icon="{ item, active }">
<image
:src="active ? item.iconActive : item.icon"
style="width: 40rpx; height: 40rpx;"
/>
</template>
</tri-quicken-side-nav>
</template>
自定义底部
<template>
<tri-quicken-side-nav :items="items">
<template #footer>
<view class="user-info">
<image src="/static/avatar.png" class="avatar" />
<text>用户名</text>
</view>
</template>
</tri-quicken-side-nav>
</template>
带角标的导航
<script>
export default {
data() {
return {
navItems: [
{ id: 'messages', label: '消息中心', icon: '💬', badge: 99 },
{ id: 'tasks', label: '待办任务', icon: '📋', badge: 'NEW' }
]
}
}
}
</script>
使用 iconMap 图标映射
通过 iconMap 属性,可以将简短的图标名称映射到实际的图片路径,方便统一管理图标资源:
<template>
<tri-quicken-side-nav
v-model="activeId"
:items="navItems"
:icon-map="iconMap"
/>
</template>
<script>
export default {
data() {
return {
activeId: 'home',
// 图标映射表
iconMap: {
'home': '/static/icons/home.png',
'user': '/static/icons/user.png',
'settings': '/static/icons/settings.png'
},
// 导航数据中使用简短的图标名称
navItems: [
{ id: 'home', label: '首页', icon: 'home' },
{ id: 'user', label: '用户管理', icon: 'user' },
{ id: 'settings', label: '设置', icon: 'settings' }
]
}
}
}
</script>
注意事项
- 使用分组模式时,
sections 的优先级高于 items
icon 字段支持图片路径(以 /、http、data: 开头)、文字/emoji,以及 iconMap 中定义的 key
- 手风琴模式仅对同级菜单生效
- 主题相关的颜色属性(如
backgroundColor、textColor 等)会覆盖主题预设值