Menu 菜单

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

提示

如果你想覆盖 el-menu 的默认高度,可以使用以下 CSS

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

顶栏

顶栏菜单可以用于多种场景。

默认情况下菜单是垂直的,但你可以通过将 mode 属性设置为 'horizontal' 来将其更改为水平。此外,你可以使用 sub-menu 组件创建二级菜单。Menu 提供了 background-colortext-coloractive-text-color 来自定义颜色。

左侧和右侧

你可以使菜单项居左或居右。

带有子菜单的垂直菜单。

你可以使用 el-menu-item-group 组件来创建一个菜单组,组名由 title 属性或命名插槽决定。

默认颜色
自定义颜色

Collapse 折叠面板

垂直菜单可以折叠。

弹出层偏移 2.4.4

带有 popperOffset 的子菜单将覆盖菜单的 popper-offset

名称描述类型默认值
mode菜单显示模式枚举vertical
收起是否折叠收起菜单(仅在垂直模式下可用)booleanfalse
ellipsis是否使用省略显示(仅在水平模式下可用)booleantrue
ellipsis-icon 2.4.4自定义省略图标(仅在水平模式且 ellipsis 为 true 时可用)string / Component
popper-offset 2.4.4弹出层的偏移量(对所有子菜单生效)number6
default-active页面加载时默认激活的菜单的 indexstring''
default-openeds当前打开的子菜单的 index 数组array[]
unique-opened是否只保持一个子菜单的展开booleanfalse
menu-trigger子菜单触发方式,仅在 mode 为 'horizontal' 时生效枚举悬浮时
router是否启用 vue-router 模式。 启用该模式会在激活导航时以 index 作为 path 进行路由跳转。 使用 default-active 来设置加载时的激活项。booleanfalse
collapse-transition是否启用折叠动画booleantrue
popper-effect 2.2.26当菜单折叠时,Tooltip 的主题,内置主题:dark / lightenum / string暗黑模式
close-on-click-outside 2.4.4可选,点击外部是否折叠菜单booleanfalse
popper-class 2.5.0所有弹出菜单和标题 Tooltip 的自定义类名string
popper-style 2.11.5所有弹出菜单和标题 Tooltip 的自定义样式string / object
show-timeout 2.5.0控制所有菜单在显示前的超时时间number300
hide-timeout 2.5.0控制所有菜单在隐藏前的超时时间number300
background-color deprecated菜单的背景颜色(十六进制格式)(请改在样式类中使用 --el-menu-bg-colorstring#ffffff
text-color deprecated菜单的文本颜色(十六进制格式)(请改在样式类中使用 --el-menu-text-colorstring#303133
active-text-color deprecated当前激活菜单项的文本颜色(十六进制格式)(请改在样式类中使用 --el-menu-active-colorstring#409eff
persistent 2.9.5当菜单不活跃且 persistentfalse 时,下拉菜单将被销毁booleantrue
名称描述类型
select菜单激活回调Function
open子菜单展开回调Function
关闭子菜单收起回调Function
名称描述子标签
default自定义默认内容SubMenu / Menu-Item / Menu-Item-Group
名称描述类型
open展开指定的子菜单,参数为该子菜单的 indexFunction
关闭收起指定的子菜单,参数为该子菜单的 indexFunction
handleResize手动触发菜单宽度重新计算Function
updateActiveIndex 2.9.8设置激活菜单的 indexFunction
名称描述类型默认值
index 必填唯一标识string
popper-class弹出菜单的自定义类名string
popper-style 2.11.5弹出菜单的自定义样式string / object
show-timeout展开子菜单前的超时时间(默认继承菜单的 show-timeoutnumber
hide-timeout收起子菜单前的超时时间(默认继承菜单的 hide-timeoutnumber
disabled是否禁用子菜单booleanfalse
teleported是否将弹出菜单 teleport 至 body。默认情况下,一级子菜单为 true,其他子菜单为 falsebooleanundefined
popper-offset弹出层的偏移量(覆盖菜单的 popper-offsetnumber
expand-close-icon当菜单展开且子菜单关闭时的图标,expand-close-iconexpand-open-icon 需要同时传入才能生效string / Component
expand-open-icon当菜单展开且子菜单打开时的图标,expand-open-iconexpand-close-icon 需要同时传入才能生效string / Component
collapse-close-icon当菜单折叠且子菜单关闭时的图标,collapse-close-iconcollapse-open-icon 需要同时传入才能生效string / Component
collapse-open-icon当菜单折叠且子菜单打开时的图标,collapse-open-iconcollapse-close-icon 需要同时传入才能生效string / Component
名称描述子标签
default自定义默认内容SubMenu / Menu-Item / Menu-Item-Group
title自定义标题内容
名称描述类型默认值
index 必填唯一标识string
routeVue Router 路由位置参数string / object
disabled是否禁用booleanfalse
名称描述类型
click点击菜单项时的回调,参数为该菜单项实例Function
名称描述
default自定义默认内容
title自定义标题内容
名称描述类型默认值
title分组标题string
名称描述子标签
default自定义默认内容Menu-Item
title自定义分组标题

类型声明

显示声明
ts
/**
 * @param index index of activated menu
 * @param indexPath index path of activated menu
 * @param item the selected menu item
 * @param routerResult result returned by `vue-router` if `router` is enabled
 */
type MenuSelectEvent = (
  index: string,
  indexPath: string[],
  item: MenuItemClicked,
  routerResult?: Promise<void | NavigationFailure>
) => void

/**
 * @param index index of expanded sub-menu
 * @param indexPath index path of expanded sub-menu
 */
type MenuOpenEvent = (index: string, indexPath: string[]) => void

/**
 * @param index index of collapsed sub-menu
 * @param indexPath index path of collapsed sub-menu
 */
type MenuCloseEvent = (index: string, indexPath: string[]) => void

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

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

来源

组件样式文档

贡献者