ElementUIplus --- el-menu 菜单折叠的情况下 二级菜单选中 一级菜单lcon 高亮 样式设置
submenu 部分代码示例
<template> <template v-for="(item, index) in props.children" :key="index"> <el-sub-menu v-if="!item.meta.hidden && item.children" :index="item.name"> <template #title> <el-icon> <span :class="[item.icon, 'iconfont']"></span> </el-icon> <span>{{ i18n.t(item.name) }}</span> </template> <!-- 递归嵌套 --> <SubMenu :children="item.children"></SubMenu> </el-sub-menu> <el-menu-item :index="item.name" :route="item.path" v-else-if="!item.meta.hidden"> <el-icon> <component :is="item.icon" :class="[item.icon, 'iconfont']" /> </el-icon> <template #title> <span>{{ i18n.t(item.name) }}</span> </template> </el-menu-item> </template> </template>
submenu.scss 部分代码示例
<style lang="scss"> .el-sub-menu .el-sub-menu__title { font-size: 14px; height: 40px; } .el-sub-menu .el-sub-menu__title:hover { color: rgba(72, 118, 255, 1) !important; background-color: transparent !important; border-radius: 8px; } .el-sub-menu .el-menu-item { font-size: 14px; height: 40px; &:hover { color: rgba(72, 118, 255, 1); background-color: rgba(234, 239, 255, 1) !important; border-radius: 8px; } &.is-active { color: rgba(72, 118, 255, 1) !important; background-color: rgba(234, 239, 255, 1) !important; border-radius: 8px; } } .el-menu--collapse { .is-active { .el-sub-menu__title { color: rgba(72, 118, 255, 1) !important; background-color: rgba(234, 239, 255, 1) !important; border-radius: 8px; } } } .el-menu-item { font-size: 14px; height: 40px; &:hover { color: rgba(72, 118, 255, 1); background-color: rgba(234, 239, 255, 1) !important; border-radius: 8px; } &.is-active { color: rgba(72, 118, 255, 1) !important; background-color: rgba(234, 239, 255, 1) !important; border-radius: 8px; } } </style>
home.vue 代码示例
<el-container class="classic-content"> <div class="aside-box" :style="{ width: isCollapse ? '65px' : '235px' }"> <el-scrollbar> <el-menu :collapse="isCollapse" class="el-menu-list" :collapse-transition="false" router :default-active="defaultActive" mode="vertical"> <SubMenu :children="store.state.menu.menus[0].children"></SubMenu> </el-menu> </el-scrollbar> </div> <el-main> <router-view v-slot="{ Component }"> <keep-alive :include="keepAliveList"> <component :is="Component" :key="route.fullPath" /> </keep-alive> </router-view> </el-main> </el-container> </el-container>
home.scss 部分代码示例
<style scoped lang="scss"> .el-menu { height: 100%; border: none; } .el-main { height: calc(100vh - 56px); background: var(--el-color-info-light-9); padding: 20px; } .classic-content { display: flex; height: calc(100vh - 56px); :deep(.el-aside) { // width: auto; .aside-box { display: flex; flex-direction: column; height: 100%; transition: width 0.1s; position: relative; .el-menu { width: 100%; overflow-x: hidden; border-right: none; } } } }
<style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)