Menu 菜单
网站的导航菜单,可以横着放在页头,也可以竖着放在侧边栏,支持多级子菜单和折叠。由 HuiMenu、HuiSubMenu、HuiMenuItem 三个组件配合使用。
引入
import { HuiMenu, HuiSubMenu, HuiMenuItem } from '@nscode/handy-ui'
基础用法
默认是纵向菜单。每个 HuiMenuItem 和 HuiSubMenu 都要有一个唯一的 index。default-active 指定一开始选中哪一项,点菜单项时触发 select,参数里有这一项的 index 和它所在的各级子菜单的 index。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem } from '@nscode/handy-ui'
const selected = ref('1')
const path = ref<string[]>([])
const handleSelect = (index: string, indexPath: string[]) => {
selected.value = index
path.value = indexPath
}
</script>
<template>
<HuiMenu default-active="1" style="width: 240px" @select="handleSelect">
<HuiMenuItem index="1">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理">
<HuiMenuItem index="2-1">用户管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3">消息中心</HuiMenuItem>
</HuiMenu>
<p style="margin-top: 12px">
选中:{{ selected }},所在子菜单:{{ path.length ? path.join(' / ') : '无' }}
</p>
</template>
菜单方向
mode 可选 vertical(纵向,默认)和 horizontal(横向)。
- 纵向菜单竖着排,子菜单就地展开在标题下面,适合放在侧边栏。
- 横向菜单横着排,高 60px,适合放在页头。子菜单在标题下方以浮层弹出,鼠标移入 150 毫秒后打开,移出 150 毫秒后收起;多级子菜单在上一级浮层的右侧弹出。点了某个菜单项后,浮层全部收起。菜单项放不下时,菜单可以横向滚动,子菜单标题不会被压缩。
<template>
<HuiSpace direction="vertical" fill size="large">
<div>
<p class="row-label">horizontal</p>
<HuiMenu mode="horizontal" default-active="1">
<HuiMenuItem index="1">首页</HuiMenuItem>
<HuiSubMenu index="2" title="产品中心">
<HuiMenuItem index="2-1">产品列表</HuiMenuItem>
<HuiMenuItem index="2-2">产品分类</HuiMenuItem>
<HuiSubMenu index="2-3" title="更多">
<HuiMenuItem index="2-3-1">产品统计</HuiMenuItem>
<HuiMenuItem index="2-3-2">产品日志</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
<HuiMenuItem index="3">关于我们</HuiMenuItem>
</HuiMenu>
</div>
<div>
<p class="row-label">vertical</p>
<HuiMenu mode="vertical" default-active="1" style="width: 240px">
<HuiMenuItem index="1">首页</HuiMenuItem>
<HuiSubMenu index="2" title="产品中心">
<HuiMenuItem index="2-1">产品列表</HuiMenuItem>
<HuiMenuItem index="2-2">产品分类</HuiMenuItem>
<HuiSubMenu index="2-3" title="更多">
<HuiMenuItem index="2-3-1">产品统计</HuiMenuItem>
<HuiMenuItem index="2-3-2">产品日志</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
<HuiMenuItem index="3">关于我们</HuiMenuItem>
</HuiMenu>
</div>
</HuiSpace>
</template>
<style scoped>
.row-label {
margin: 0 0 8px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
横向菜单也可以带图标、禁用项:
<template>
<HuiMenu mode="horizontal" default-active="1">
<HuiMenuItem index="1" icon="home">首页</HuiMenuItem>
<HuiSubMenu index="2" title="产品中心" icon="apps">
<HuiMenuItem index="2-1" icon="file">产品列表</HuiMenuItem>
<HuiMenuItem index="2-2" icon="folder">产品分类</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3" icon="bell">消息</HuiMenuItem>
<HuiMenuItem index="4" icon="lock" disabled>管理后台</HuiMenuItem>
</HuiMenu>
</template>
多级子菜单
纵向菜单里,子菜单就地展开在标题下面,点标题展开或收起,子级按层级缩进。选中某个子菜单里的项时,它所在的各级子菜单标题也会显示成激活色。
<template>
<HuiMenu default-active="2-2-1" style="width: 240px">
<HuiMenuItem index="1">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理">
<HuiMenuItem index="2-1">用户管理</HuiMenuItem>
<HuiSubMenu index="2-2" title="权限管理">
<HuiMenuItem index="2-2-1">角色管理</HuiMenuItem>
<HuiMenuItem index="2-2-2">菜单管理</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
</HuiMenu>
</template>
默认展开和默认激活
default-active 指向某个子菜单里的项时,挂载后会自动展开它所在的各级子菜单(只在纵向、没有折叠时这样做)。default-openeds 指定一开始展开哪些子菜单。
这两个属性运行时修改也会生效:改 default-active 会选中新的项并展开它所在的子菜单;default-openeds 的内容变了,展开的子菜单会重置成新的列表。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiButton, HuiSpace } from '@nscode/handy-ui'
const active = ref('2-1')
const openeds = ref(['3'])
</script>
<template>
<HuiSpace wrap style="margin-bottom: 12px">
<HuiButton @click="active = '3-2'">选中“操作日志”</HuiButton>
<HuiButton @click="active = '2-2'">选中“角色管理”</HuiButton>
<HuiButton @click="openeds = ['2', '3']">展开全部</HuiButton>
<HuiButton @click="openeds = []">收起全部</HuiButton>
</HuiSpace>
<HuiMenu :default-active="active" :default-openeds="openeds" style="width: 240px">
<HuiMenuItem index="1">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理">
<HuiMenuItem index="2-1">用户管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="3" title="日志">
<HuiMenuItem index="3-1">登录日志</HuiMenuItem>
<HuiMenuItem index="3-2">操作日志</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
只展开一个子菜单(手风琴)
unique-opened 为 true 时,展开一个子菜单会自动收起其他不相关的子菜单,它自己的上级不受影响。下面左边是默认,可以同时展开多个;右边开了 unique-opened:
<template>
<HuiSpace align="start" size="large" wrap>
<HuiMenu style="width: 240px">
<HuiSubMenu index="1" title="系统管理">
<HuiMenuItem index="1-1">用户管理</HuiMenuItem>
<HuiMenuItem index="1-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="2" title="日志">
<HuiMenuItem index="2-1">登录日志</HuiMenuItem>
<HuiMenuItem index="2-2">操作日志</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
<HuiMenu unique-opened style="width: 240px">
<HuiSubMenu index="1" title="系统管理">
<HuiMenuItem index="1-1">用户管理</HuiMenuItem>
<HuiMenuItem index="1-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="2" title="日志">
<HuiMenuItem index="2-1">登录日志</HuiMenuItem>
<HuiSubMenu index="2-2" title="操作日志">
<HuiMenuItem index="2-2-1">新增记录</HuiMenuItem>
<HuiMenuItem index="2-2-2">删除记录</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
</HuiMenu>
</HuiSpace>
</template>
图标和折叠
HuiMenuItem 和 HuiSubMenu 的 icon 在文字前面显示一个图标(HuiIcon 的 name)。collapse 为 true 时菜单宽度变成 64px,顶层的菜单项和子菜单标题只显示图标;子菜单改成在右侧以浮层弹出,悬停或点击标题打开。切到折叠时,已经展开的子菜单会全部收起。
折叠模式下顶层项要写 icon,否则只剩一块空白。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiSwitch } from '@nscode/handy-ui'
const collapsed = ref(false)
</script>
<template>
<div style="margin-bottom: 12px">
<HuiSwitch v-model="collapsed" active-text="折叠" />
</div>
<HuiMenu :collapse="collapsed" default-active="1">
<HuiMenuItem index="1" icon="home">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理" icon="setting">
<HuiMenuItem index="2-1" icon="user">用户管理</HuiMenuItem>
<HuiMenuItem index="2-2" icon="users">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3" icon="bell">消息中心</HuiMenuItem>
</HuiMenu>
</template>
禁用
HuiMenuItem 或 HuiSubMenu 的 disabled 为 true 时,点击、悬停和键盘都不起作用,Tab 键也会跳过它。子菜单里的项也可以单独禁用。
<template>
<HuiMenu style="width: 240px" :default-openeds="['4']">
<HuiMenuItem index="1">工作台</HuiMenuItem>
<HuiMenuItem index="2" disabled>数据大屏(建设中)</HuiMenuItem>
<HuiSubMenu index="3" title="系统管理" disabled>
<HuiMenuItem index="3-1">用户管理</HuiMenuItem>
</HuiSubMenu>
<HuiSubMenu index="4" title="日志">
<HuiMenuItem index="4-1">登录日志</HuiMenuItem>
<HuiMenuItem index="4-2" disabled>审计日志(无权限)</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
自定义颜色
background-color、text-color、active-text-color 分别设置菜单的背景色、文字色和选中项的文字色,横向、折叠模式下的浮层也用同样的颜色。值会写进内联样式,可以用主题变量。
<template>
<HuiSpace direction="vertical" fill>
<HuiMenu
mode="horizontal"
default-active="1"
background-color="var(--hui-color-primary-darker)"
text-color="var(--hui-color-white)"
active-text-color="var(--hui-color-warning)"
>
<HuiMenuItem index="1" icon="home">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理" icon="setting">
<HuiMenuItem index="2-1">用户管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="3" icon="bell">消息中心</HuiMenuItem>
</HuiMenu>
<HuiMenu
default-active="1"
background-color="var(--hui-color-primary-darker)"
text-color="var(--hui-color-white)"
active-text-color="var(--hui-color-warning)"
style="width: 240px"
>
<HuiMenuItem index="1" icon="home">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理" icon="setting">
<HuiMenuItem index="2-1">用户管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</HuiSpace>
</template>
自定义标题
HuiMenuItem 的文字可以写在默认插槽里,也可以写在 title 插槽里,两个都写时只显示 title 插槽。折叠模式下顶层项隐藏的就是这部分内容,图标仍然显示。
HuiSubMenu 的 title 插槽替换掉图标和标题文字(右边的箭头保留)。标题行是两端对齐的,插槽里有多个元素时用一个元素包起来,否则它们会被拉开。折叠模式下组件分不清插槽里哪部分是图标、哪部分是文字,不会隐藏它,所以要折叠的菜单请用 icon 和 title 属性。
<script setup lang="ts">
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiIcon } from '@nscode/handy-ui'
</script>
<template>
<HuiMenu style="width: 240px">
<HuiMenuItem index="1">
<template #title>工作台</template>
</HuiMenuItem>
<HuiSubMenu index="2">
<template #title>
<span>
<HuiIcon name="mail" />
消息中心
<span style="color: var(--hui-text-color-secondary)">(12 条未读)</span>
</span>
</template>
<HuiMenuItem index="2-1">站内信</HuiMenuItem>
<HuiMenuItem index="2-2">系统通知</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
路由模式
router 为 true 时,点击菜单项先触发 select,再调用 app.config.globalProperties.$router.push(route ?? index)。route 可以是路径字符串或路由对象;没传时使用 index 作为目标。
导航等待期间保留原高亮,成功后按实际落地的完整路由(包含查询参数)匹配菜单。重定向后高亮对应菜单,没有匹配项则清除高亮;多个菜单指向相同目标时优先本次点击项。守卫取消、重复导航或导航异常不改变高亮,异常在组件内处理并输出 [HandyUI] 诊断。较早导航、卸载前的导航,以及业务在等待中显式修改 default-active 前的导航,都不会覆盖后续高亮。
select 是即时点击通知,不代表导航成功。通过浏览器前进、后退或业务代码跳转时,仍需把业务计算的激活项绑定到 default-active,菜单不会主动监听所有路由变化。组件使用应用 app.use(router) 后提供的 $router;没有注册路由时按普通菜单同步选择。
<script setup lang="ts">
import { useRoute } from 'vue-router'
import { HuiMenu, HuiMenuItem } from '@nscode/handy-ui'
const route = useRoute()
</script>
<template>
<HuiMenu router :default-active="route.path" style="width: 240px">
<HuiMenuItem index="/dashboard" route="/dashboard">工作台</HuiMenuItem>
<HuiMenuItem index="/users" :route="{ path: '/users', query: { page: 1 } }"
>用户管理</HuiMenuItem
>
</HuiMenu>
</template>
浮层的自定义类名
HuiSubMenu 的 popper-class 会加到子菜单的列表 ul(类名 hui-sub-menu__menu)上。横向、折叠模式下这个列表是浮层,挂在 body 下,所以:
- 样式不要写在
scoped里,要写成全局样式; - 不要用
.hui-menu .my-popup这类以菜单为祖先的后代选择器,直接用.my-popup。
<template>
<HuiMenu mode="horizontal">
<HuiSubMenu index="1" title="更多" popper-class="my-menu-popup">
<HuiMenuItem index="1-1">帮助文档</HuiMenuItem>
<HuiMenuItem index="1-2">意见反馈</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
<style>
.my-menu-popup {
min-width: 260px;
border: 1px solid var(--hui-border-color);
}
</style>
监听展开和收起
子菜单展开时触发 open,收起时触发 close,参数是这个子菜单的 index 和它的各级上级子菜单的 index。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem } from '@nscode/handy-ui'
const log = ref('还没有展开或收起')
const handleOpen = (index: string, indexPath: string[]) => {
log.value = `open:${index},上级:${indexPath.length ? indexPath.join(' / ') : '无'}`
}
const handleClose = (index: string, indexPath: string[]) => {
log.value = `close:${index},上级:${indexPath.length ? indexPath.join(' / ') : '无'}`
}
</script>
<template>
<HuiMenu style="width: 240px" @open="handleOpen" @close="handleClose">
<HuiSubMenu index="1" title="系统管理">
<HuiMenuItem index="1-1">用户管理</HuiMenuItem>
<HuiSubMenu index="1-2" title="权限管理">
<HuiMenuItem index="1-2-1">角色管理</HuiMenuItem>
<HuiMenuItem index="1-2-2">菜单管理</HuiMenuItem>
</HuiSubMenu>
</HuiSubMenu>
<HuiSubMenu index="2" title="日志">
<HuiMenuItem index="2-1">登录日志</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
<p style="margin-top: 12px">{{ log }}</p>
</template>
通过方法展开、收起
通过 HuiMenu 的 ref 调用 open(index, indexPath)、close(index, indexPath)。indexPath 是这个子菜单的各级上级子菜单的 index,顶层子菜单传 [];unique-opened 时靠它判断哪些子菜单要保留。ref 上还能读到当前选中项 activeIndex 和展开的子菜单 openedMenus。
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiSubMenu, HuiMenuItem, HuiButton, HuiSpace } from '@nscode/handy-ui'
const menuRef = ref<InstanceType<typeof HuiMenu>>()
const state = ref('')
const readState = () => {
const menu = menuRef.value
if (!menu) return
const opened = Array.from(menu.openedMenus)
state.value = `activeIndex:${menu.activeIndex || '无'},openedMenus:${opened.length ? opened.join('、') : '无'}`
}
</script>
<template>
<div style="margin-bottom: 12px">
<HuiSpace wrap>
<HuiButton @click="menuRef?.open('2', [])">展开系统管理</HuiButton>
<HuiButton @click="menuRef?.close('2', [])">收起系统管理</HuiButton>
<HuiButton @click="readState">读取状态</HuiButton>
<span>{{ state }}</span>
</HuiSpace>
</div>
<HuiMenu ref="menuRef" default-active="1" style="width: 240px">
<HuiMenuItem index="1">工作台</HuiMenuItem>
<HuiSubMenu index="2" title="系统管理">
<HuiMenuItem index="2-1">用户管理</HuiMenuItem>
<HuiMenuItem index="2-2">角色管理</HuiMenuItem>
</HuiSubMenu>
</HuiMenu>
</template>
键盘操作
菜单使用一个Tab停留点。进入后用方向键导航,纵向展开时包含已经展开的各级内嵌项;每层浮层独立导航。禁用项和隐藏分支不参与,父组件重绘不会主动抢走外部焦点。输入法组合、229和Ctrl/Meta/Alt组合键留给输入或系统。
| 按键 | 作用 |
|---|---|
↑、↓ | 纵向展开时按可见DOM顺序循环穿过内嵌子项;浮层里只在当前层循环 |
←、→ | 横向菜单的顶层:在顶层各项之间循环移动焦点 |
Enter、空格 | 在菜单项上:选中这一项。在子菜单标题上:内嵌时展开或收起;浮层模式下打开浮层并聚焦第一项 |
↓ | 横向菜单顶层的子菜单标题上:打开浮层并聚焦第一项 |
→ | 向右弹出的子菜单标题上(多级浮层里的、折叠模式顶层的):打开浮层并聚焦第一项 |
Esc | 浮层里:收起当前这一层浮层,焦点回到它的标题 |
← | 向右弹出的浮层里:同 Esc |
Home、End | 到当前可见列表的首项、末项,跳过禁用项 |
| 可打印字符 | 按文字前缀跳转,500ms内连续输入组成前缀;重复同一字符在匹配项之间循环 |
<script setup lang="ts">
import { ref } from 'vue'
import { HuiMenu, HuiMenuItem, HuiSubMenu, HuiSpace } from '@nscode/handy-ui'
const selected = ref('尚未选择')
</script>
<template>
<HuiSpace direction="vertical" fill>
<span>Tab进入后试按上下、Home/End或B:{{ selected }}</span>
<HuiMenu :default-openeds="['group']" @select="selected = $event">
<HuiMenuItem index="alpha">Alpha 首页</HuiMenuItem>
<HuiSubMenu index="group" title="Group 分组">
<HuiMenuItem index="beta">Beta 报表</HuiMenuItem>
<HuiMenuItem index="bravo">Bravo 任务</HuiMenuItem>
<HuiMenuItem index="disabled" disabled>不可选择</HuiMenuItem>
</HuiSubMenu>
<HuiMenuItem index="charlie">Charlie 设置</HuiMenuItem>
</HuiMenu>
</HuiSpace>
</template>
HuiMenu Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| mode | 'horizontal' | 'vertical' | 'vertical' | 菜单方向 |
| defaultActive | string | '' | 选中项的 index。运行时修改会选中新的项,并展开它所在的子菜单 |
| defaultOpeneds | string[] | [] | 一开始展开的子菜单的 index。内容变了时,展开的子菜单重置成新的列表 |
| collapse | boolean | false | 是否折叠(只在纵向菜单上使用)。折叠后宽 64px,顶层只显示图标 |
| backgroundColor | string | - | 菜单的背景色,浮层也用这个颜色 |
| textColor | string | - | 菜单的文字色,浮层也用这个颜色 |
| activeTextColor | string | - | 选中项和它所在子菜单标题的文字色。不传时用主色 |
| router | boolean | false | 点击时调用 $router.push(route ?? index),成功后按落地路由更新高亮 |
| uniqueOpened | boolean | false | 是否只保持一个子菜单展开 |
HuiSubMenu Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| index | string | - | 唯一标识,必填 |
| title | string | '' | 标题文字。写了 title 插槽时不显示 |
| icon | string | - | 标题前的图标名(HuiIcon 的 name),折叠模式下顶层只显示它 |
| disabled | boolean | false | 是否禁用 |
| popperClass | string | '' | 加在子菜单列表 ul 上的类名。浮层挂在 body 下,样式要写成全局样式 |
HuiMenuItem Props
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| index | string | - | 唯一标识,必填 |
| route | string | Record<string, unknown> | - | 路由目标。HuiMenu 开了 router 时,点击后传给 $router.push |
| icon | string | - | 文字前的图标名(HuiIcon 的 name),折叠模式下顶层只显示它 |
| disabled | boolean | false | 是否禁用 |
HuiMenu Events
| 事件 | 回调参数 | 说明 |
|---|---|---|
| select | (index: string, indexPath: string[], item: MenuItemContext) | 点菜单项(或按回车、空格)时立即触发,不代表路由导航成功,点已选项也触发。indexPath 是所在的各级子菜单 index,不包含自己 |
| open | (index: string, indexPath: string[]) | 子菜单展开时触发。indexPath 是这个子菜单的各级上级子菜单的 index |
| close | (index: string, indexPath: string[]) | 子菜单收起时触发,参数同 open |
HuiMenu Slots
| 插槽 | 作用域参数 | 说明 |
|---|---|---|
| default | - | 放 HuiMenuItem、HuiSubMenu |
HuiSubMenu Slots
| 插槽 | 作用域参数 | 说明 |
|---|---|---|
| default | - | 子菜单里的 HuiMenuItem、HuiSubMenu |
| title | - | 标题内容,替换掉图标和 title 文字,右边的箭头保留 |
HuiMenuItem Slots
| 插槽 | 作用域参数 | 说明 |
|---|---|---|
| default | - | 菜单项的文字 |
| title | - | 菜单项的文字,写了它时不显示默认插槽。折叠时顶层隐藏 |
HuiMenu 暴露的属性和方法
通过组件的 ref 读取、调用。
| 名称 | 类型 | 说明 |
|---|---|---|
| activeIndex | string | 当前选中项的 index |
| openedMenus | Set<string> | 当前展开的子菜单的 index |
| open | (index: string, indexPath: string[]) => void | 展开子菜单并触发 open,已经展开时什么也不做。不检查禁用,也不展开上级 |
| close | (index: string, indexPath: string[]) => void | 收起子菜单并触发 close,已经收起时什么也不做 |
类型
import type {
MenuMode,
MenuRoute,
MenuProps,
SubMenuProps,
MenuItemProps,
MenuItemContext
} from '@nscode/handy-ui'
import type { Ref } from 'vue'
type MenuMode = 'horizontal' | 'vertical'
type MenuRoute = string | Record<string, unknown>
interface MenuProps {
mode?: MenuMode
defaultActive?: string
defaultOpeneds?: string[]
collapse?: boolean
backgroundColor?: string
textColor?: string
activeTextColor?: string
router?: boolean
uniqueOpened?: boolean
}
interface SubMenuProps {
index: string
title?: string
disabled?: boolean
popperClass?: string
icon?: string
}
interface MenuItemProps {
index: string
route?: MenuRoute
disabled?: boolean
icon?: string
}
/** select 事件的第三个参数 */
interface MenuItemContext {
index: string
rootMenu: MenuContext
parentMenu: SubMenuContext | null
active: Ref<boolean>
disabled: Ref<boolean>
/** 所在的各级子菜单的 index,不包含自己 */
indexPath: string[]
route?: MenuRoute
}
另外还导出了 MenuEmits、MenuContext、SubMenuContext 和注入用的 MENU_INJECTION_KEY、SUB_MENU_INJECTION_KEY,自己写和 HuiMenu 配合的子组件时才用得到。