Menu 导航菜单

为网站提供导航功能的菜单。

TIP

若要覆盖菜单默认高度,可使用如下样式:

css
.u-menu--horizontal {
  --u-menu-horizontal-height: 100px;
}

顶栏

顶栏菜单适用于多种场景。

默认垂直布局;将 mode 设为 horizontal 可切换为水平。可使用子菜单组件创建二级菜单。background-colortext-coloractive-text-color 用于自定义颜色。

左右排列

可将菜单项靠左或靠右排列。

侧栏

带子菜单的垂直菜单。

使用 u-menu-item-group 创建分组;分组名由 title 属性或具名插槽决定。

Default colors
Custom colors

折叠

垂直菜单可折叠。

弹出层偏移

子菜单的 popperOffset 会覆盖菜单的 popper-offset

菜单 API

菜单 属性

名称说明类型默认值
mode菜单模式enumvertical
collapse是否折叠(仅垂直模式)booleanfalse
ellipsis是否省略(仅水平模式)booleantrue
ellipsis-icon自定义省略图标(水平且 ellipsistrue 时)string / Component
popper-offset弹出层偏移(对所有子菜单生效)number6
default-active初始激活菜单的 indexstring''
default-openeds初始展开的子菜单 index 数组array[]
unique-opened是否只允许一个子菜单展开booleanfalse
menu-trigger子菜单触发方式,仅 modehorizontal 时生效enumhover
router是否启用 vue-router;为 trueindex 作为 path 进行路由跳转,可配合 default-active 设置初始高亮booleanfalse
collapse-transition是否启用折叠动画booleantrue
popper-effect折叠时文字提示主题,内置 dark / lightenum / stringdark
close-on-click-outside点击菜单外部是否折叠菜单booleanfalse
popper-class所有弹出菜单与标题提示的自定义类名string
popper-style所有弹出菜单与标题提示的自定义样式string / object
show-timeout所有菜单显示前延迟(毫秒)number300
hide-timeout所有菜单隐藏前延迟(毫秒)number300
persistent菜单失活且为 false 时销毁下拉booleantrue

菜单 事件

名称说明类型
select激活菜单项时Function
open子菜单展开时Function
close子菜单收起时Function

菜单 插槽

名称说明子标签
default自定义内容SubMenu / Menu-Item / Menu-Item-Group

菜单 暴露

名称说明类型
open打开指定子菜单,参数为子菜单 indexFunction
close关闭指定子菜单,参数为子菜单 indexFunction
handleResize手动触发菜单宽度重算Function
updateActiveIndex设置当前激活菜单 indexFunction

子菜单 API

子菜单 属性

名称说明类型默认值
index required唯一标识string
popper-class弹出菜单自定义类名string
popper-style弹出菜单自定义样式string / object
show-timeout显示前延迟(默认继承菜单 show-timeoutnumber
hide-timeout隐藏前延迟(默认继承菜单 hide-timeoutnumber
disabled是否禁用booleanfalse
teleported是否将弹出菜单传送到 body;一级子菜单默认 true,其余默认 falsebooleanundefined
popper-offset弹出层偏移(覆盖菜单的 popper-offsetnumber
expand-close-icon菜单展开且子菜单关闭时的图标;需与 expand-open-icon 同时传入才生效string / Component
expand-open-icon菜单展开且子菜单打开时的图标;需与 expand-close-icon 同时传入才生效string / Component
collapse-close-icon菜单折叠且子菜单关闭时的图标;需与 collapse-open-icon 同时传入才生效string / Component
collapse-open-icon菜单折叠且子菜单打开时的图标;需与 collapse-close-icon 同时传入才生效string / Component

子菜单 插槽

名称说明子标签
default自定义内容SubMenu / Menu-Item / Menu-Item-Group
title自定义标题

菜单项 API

菜单项 属性

名称说明类型默认值
index required唯一标识string
routeVue Router 路由参数string / object
disabled是否禁用booleanfalse

菜单项 事件

名称说明类型
click点击菜单项时触发,参数为菜单项注册信息Function

菜单项 插槽

名称说明
default自定义内容
title自定义标题

菜单项分组 API

菜单项分组 属性

名称说明类型默认值
title分组标题string

菜单项分组 插槽

名称说明子标签
default自定义内容Menu-Item
title自定义分组标题

类型声明

展开类型声明
ts
/**
 * @param index 激活菜单索引
 * @param indexPath 激活菜单索引路径
 * @param item 选中的菜单项
 * @param routerResult 启用 `router` 时 `vue-router` 返回结果
 */
type MenuSelectEvent = (
  index: string,
  indexPath: string[],
  item: MenuItemClicked,
  routerResult?: Promise<void | NavigationFailure>
) => void

/**
 * @param index 展开的子菜单索引
 * @param indexPath 展开的子菜单索引路径
 */
type MenuOpenEvent = (index: string, indexPath: string[]) => void

/**
 * @param index 收起的子菜单索引
 * @param indexPath 收起的子菜单索引路径
 */
type MenuCloseEvent = (index: string, indexPath: string[]) => void

interface MenuItemRegistered {
  index: string
  indexPath: string[]
  active: boolean
}

interface MenuItemClicked {
  index: string
  indexPath: string[]
  route?: RouteLocationRaw
}