element-ui菜单el-menu的使用

news/2025/2/7 22:32:53/

效果演示

先给大家看一下效果吧

el-menu详解

属性名说明类型可选值默认值
mode菜单展示模式stringhorizontal / verticalvertical
collapse是否水平折叠收起菜单(仅在 mode 为 vertical 时可用)booleanfalse
ellipsis是否省略多余的子项(仅在横向模式生效)booleantrue
background-color菜单的背景颜色(十六进制格式)(已被废弃,使用--bg-colorstring#ffffff
text-color文字颜色(十六进制格式)(已被废弃,使用--text-colorstring#303133
active-text-color活动菜单项的文本颜色(十六进制格式)(已被废弃,使用--active-colorstring#409EFF
default-active页面加载时默认激活菜单的 indexstring
default-openeds默认打开的 sub-menu 的 index 的数组Array
unique-opened是否只保持一个子菜单的展开booleanfalse
menu-trigger子菜单打开的触发方式,只在 mode 为 horizontal 时有效。stringhover / clickhover
router是否启用 vue-router 模式。 启用该模式会在激活导航时以 index 作为 path 进行路由跳转 使用 default-active 来设置加载时的激活项。booleanfalse
collapse-transition是否开启折叠动画booleantrue
popper-effectTooltip 主题,内置了 dark / light 两种主题stringdark / lightdark
方法名说明参数
open展开指定的 sub-menuindex: 需要打开的 sub-menu 的 index
close收起指定的 sub-menuindex: 需要收起的 sub-menu 的 index
事件名说明回调参数
select菜单激活回调index: 选中菜单项的 index, indexPath: 选中菜单项的 index path, item: 选中菜单项, routeResult: vue-router 的返回值(如果 router 为 true)
opensub-menu 展开的回调index: 打开的 sub-menu 的 index, indexPath: 打开的 sub-menu 的 index path
closesub-menu 收起的回调index: 收起的 sub-menu 的 index, indexPath: 收起的 sub-menu 的 index path
插槽名说明子标签
自定义默认内容SubMenu / Menu-Item / Menu-Item-Group
属性名说明类型可选值默认值
index唯一标志string
popper-class为 popper 添加类名string
show-timeout展开 sub-menu 的延时number300
hide-timeout收起 sub-menu 的延时number300
disabled是否禁用booleanfalse
popper-append-to-body(已废弃)是否将弹出菜单插入至 body 元素。 在菜单的定位出现问题时,可尝试修改该属性boolean一级子菜单:true / 非一级子菜单:false
teleported是否将 popup 的下拉列表插入至 body 元素boolean一级子菜单:true / 非一级子菜单:false
popper-offset弹出窗口偏移number6
expand-close-icon父菜单展开且子菜单关闭时的图标, expand-close-iconexpand-open-icon 需要一起配置才能生效string | Component
expand-open-icon父菜单展开且子菜单打开时的图标, expand-open-iconexpand-close-icon 需要一起配置才能生效string | Component
collapse-close-icon父菜单收起且子菜单关闭时的图标, expand-close-iconexpand-open-icon 需要一起配置才能生效string | Component
collapse-open-icon父菜单收起且子菜单打开时的图标, expand-open-iconexpand-close-icon 需要一起配置才能生效string | Component
插槽名说明子标签
自定义默认内容SubMenu / Menu-Item / Menu-Item-Group
title自定义标题内容
属性名说明类型可选值默认值
index唯一标志string/nullnull
routeVue Router 路径对象object
disabled是否禁用booleanfalse
事件名说明回调参数
click菜单点击时的回调函数el-menu-item 实例
插槽名说明
自定义默认内容
title自定义标题内容
属性名说明类型可选值默认值
title组标题string
插槽名说明子标签
默认插槽内容Menu-Item
title自定义组标题内容

直接上代码

  <!--添加动画效果:设置内部样式--><div class="slider-navs" :style="{ width: menuStore.isCollapse ? '64px' : '210px' }"><div v-if="menuStore.toggleStore" class="logo">{{ menuStore.isCollapse ? 'J' : "JKW" }}</div><!--background-color:背景颜色(只有菜单这块,菜单占多少背景占多少) text-color:文本颜色 active-text-color:选中后文本颜色:default-active="active":点击高亮(与index=""搭配,在script设置默认访问/)router:可以把点击高亮里的index的地址变为路由地址,进行路由访问:collapse:是否开启折叠面板unique-opened 是否只保持一个子菜单的展开点击的是el-sub-menu,所以el-sub-menu 的唯一性是必须的,设置index属性来保持唯一性--><el-menu background-color="rgba(255,255,255,.1)" text-color="rgb(214, 205, 251)" active-text-color="orange":default-active="active" router class="el-menu-vertical-demo" :collapse="menuStore.isCollapse" unique-opened><el-menu-item index="/home/index"><el-icon><HomeFilled /></el-icon><span>首页</span></el-menu-item><el-sub-menu index="99"><template #title><el-icon><Tickets /></el-icon><span>页面</span></template><el-menu-item index="/:pathMath(.*)*"><el-icon><Warning /></el-icon><span>404</span></el-menu-item></el-sub-menu><el-sub-menu index="1"><template #title><el-icon><Management /></el-icon><span>分析</span></template><el-menu-item index="/annlysis/Analysis1"><el-icon><Operation /></el-icon><span>样例1</span></el-menu-item></el-sub-menu><el-sub-menu index="2"><template #title><el-icon><Tools /></el-icon><span>系统</span></template><el-menu-item index="/sys/admin"><el-icon><User /></el-icon><span>用户</span></el-menu-item><el-menu-item index="/sys/role"><el-icon><CopyDocument /></el-icon><span>角色</span></el-menu-item><el-menu-item index="/sys/permission"><el-icon><Lock /></el-icon><span>权限</span></el-menu-item></el-sub-menu></el-menu></div>

<script setup>
import { ref } from 'vue';
import { useMenuStore } from "@/stores/menuStore.js";//stores
//解决页面刷新后 菜单高亮与面包屑不匹配
const menuStore = useMenuStore()
const active = ref("/")
if (localStorage.getItem("active")) {active.value = localStorage.getItem("active")
}
</script>
<style scoped>
.slider-navs {background-image: linear-gradient(135deg, #EE9AE5 10%, #5961F9 100%) !important;/*固定在左侧(position: fixed生成绝对定位的元素, 相对于浏览器窗口进行定位) */position: fixed;left: 0;top: 0;bottom: 0;/*width: 210px;*//*设置动画过渡 和<el-menu>内部的一样 */transition: 0.3s ease-in;
}.el-menu-vertical-demo {background-image: linear-gradient(to bottom right, rgb(114, 135, 254), rgb(130, 88, 186));}.logo {background-image: linear-gradient(120deg, #00e4d0, #5983e8) !important;/*需要在App.vue设置公共样式,把element menu的右边框去掉,否则对不齐 */width: 100%;height: 60px;background-color: #364e6d;font-size: 45px;font-weight: 900;color: rgb(124, 101, 215);text-align: center;/*左右居中 */line-height: 60px;/*上下居中:和高度保持一致 */
}.icon {width: 16px;height: 16px;margin-right: 5px;/*让图标和文字有空隙 */
}
</style>

app.vue全局样式的设计

/**侧边栏样式修改 */
.el-menu{border-radius: 5px!important;background-image: linear-gradient(135deg, #EE9AE5 10%, #5961F9 100%) !important;}
.el-menu-item{border-radius: 15px!important;
}
.el-menu-item.is-active {font-weight: 900!important;font-size: 20px!important;color: #c1ecef!important;
}


http://www.ppmy.cn/news/98174.html

相关文章

jQuery-从左到右、从右到左

<!DOCTYPE html> <html> <head> <meta http-equiv"Content-Type" content"text/html; charsetUTF-8"> <title>从左到右、从右到左</title> <style type"text/css"> select { …

Windows 同时安装 MySQL5 和 MySQL8 版本

&#x1f44f;作者简介&#xff1a;大家好&#xff0c;我是Rockey&#xff0c;不知名企业的不知名开发着 &#x1f525;如果感觉博主的文章还不错的话&#xff0c;请&#x1f44d;三连支持&#x1f44d;一下博主哦 &#x1f4dd;联系方式&#xff1a;he18339193956&#xff0c;…

shell脚本入门-编写格式以及执行方式

Shell介绍 通过编写shell命令发送给linux内核去执行&#xff0c;操作就是计算机硬件&#xff0c;所以Shell命令是用户操作计算机硬件的桥梁 Shell是命令&#xff0c;类似与windows系统的Dos命令 Shell是一门程序设计语言&#xff0c;shell里面含有变量&#xff0c;函数&#xf…

day41_servlet

今日内容 零、 复习昨日 一、Cookie 二、Session 三、拦截器 四、登录认证、全局编码格式 零、 复习昨日 注解 热部署 请求转发 重定向 路径问题 总结使用经验: 无论请求路径是多层是单层,在写路径时都从/开始,即从根开始如果是服务器动作,从/开始直接写如果是浏览器动作,从/开…

【外企面试】Java技术管理与架构面试参考

文章目录 Questions Based On Self-IntroductionCan you explain the key differences between monolithic and microservices architectures, and what factors would make you choose one over the other?How do you ensure data consistency and integrity when working wi…

基于深度学习mediapipe的人脸打码人脸模糊教程pyqt5界面附源码

一、人脸识别 人脸识别是一门比较成熟的技术。 它的身影随处可见&#xff0c;刷脸支付&#xff0c;信息审核&#xff0c;监控搜索&#xff0c;人脸打码等。 更多的时候&#xff0c;它是方便了我们的生活&#xff0c;足不出户&#xff0c;就可以实现各种 APP 的实名认证&…

基于springboot + vue 的学生成绩管理系统

基于springboot vue实现的学生成绩管理系统 主要模块&#xff1a; 1&#xff09;学生模块&#xff1a;我的成绩、成绩统计、申述管理、修改密码 2&#xff09;教师模块&#xff1a;任务管理、对学生班级任务安排、班级学生的成绩查看、申述管理 3&#xff09;管理员模块&…

一文带你了解MySQL之基于规则的优化

前言&#xff1a; 大家别忘了MySQL本质上是一个软件&#xff0c;MySQL的并不能要求使用这个软件的人人都是数据库的高手&#xff0c;就像我写这篇文章的时候并不能要求各位在学之前就会了里边的知识。也就是说我们无法避免某些小伙伴写一些执行起来十分耗费性能的语句。即使是…