Menu 菜单

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

提示

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

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

顶栏

顶栏菜单可以在各种场景中使用。

左右结构

带有子菜单的垂直菜单。

Collapse 折叠面板

垂直菜单可以被折叠。

弹出框位置偏移 2.4.4

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

名称描述类型默认值
mode菜单显示模式枚举vertical
collapse菜单是否折叠(仅在 vertical 模式下可用)booleanfalse
ellipsis菜单是否省略(仅在 horizontal 模式下可用)booleantrue
ellipsis-icon 2.4.4自定义省略图标(仅在 horizontal 模式下且 ellipsis 为 true 时可用)string / Component
popper-offset 2.4.4弹出框的偏移量(对所有子菜单生效)number6
default-active页面加载时激活菜单的 indexstring''
default-openeds包含当前激活子菜单 index 的数组object[]
unique-opened是否只有一个子菜单可以被激活booleanfalse
menu-trigger子菜单如何被触发,仅在 mode 为 'horizontal' 时有效枚举悬浮时
router是否激活 vue-router 模式。如果为 true,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 已弃用Menu 的背景色(十六进制格式)(请改用样式类中的 --el-menu-bg-colorstring#ffffff
text-color 已弃用Menu 的文本颜色(十六进制格式)(请改用样式类中的 --el-menu-text-colorstring#303133
active-text-color 已弃用当前激活菜单项的文本颜色(十六进制格式)(请改用样式类中的 --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弹出菜单是否被传送到 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点击 menu-item 时的回调函数,参数是 menu-item 实例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
}

来源

组件样式文档

贡献者