el-menu折叠后文字下移

如图:

vue 复制代码
<template>
  <el-radio-group v-model="isCollapse" style="margin-bottom: 20px">
    <el-radio-button :value="false">expand</el-radio-button>
    <el-radio-button :value="true">collapse</el-radio-button>
  </el-radio-group>

  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    :collapse="isCollapse"
    @open="handleOpen"
    @close="handleClose"
  >
    <el-sub-menu index="1">
      <template #title>
        <div style="overflow: hidden;" v-if="!isCollapse">
          <el-icon><location /></el-icon>
          <span>Navigator One</span>
        </div>
        <div class="container" v-else>
          <el-icon><location /></el-icon>
          <div class="nav-coll-title">Navigator One</div>
        </div>
        
      </template>
      <el-menu-item-group>
        <template #title><span>Group One</span></template>
        <el-menu-item index="1-1">item one</el-menu-item>
        <el-menu-item index="1-2">item two</el-menu-item>
      </el-menu-item-group>
      <el-menu-item-group title="Group Two">
        <el-menu-item index="1-3">item three</el-menu-item>
      </el-menu-item-group>
      <el-sub-menu index="1-4">
        <template #title><span>item four</span></template>
        <el-menu-item index="1-4-1">item one</el-menu-item>
      </el-sub-menu>
    </el-sub-menu>
  </el-menu>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'

const isCollapse = ref(true)
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
</script>

<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.nav-collapse {
  height: 64px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
}
:deep(.el-sub-menu__title) {
  line-height: 0 !important;
}
.nav-title-collapse {
  line-height: 14px !important;
}
.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.nav-coll-title {
  line-height: 14px;
  height: 14px;
}
.el-menu--collapse {
  --el-menu-icon-width: 100px !important;
}
</style>
相关推荐
ZC跨境爬虫4 小时前
跟着 MDN 学 HTML day_9:(信件语义标记)
前端·css·笔记·ui·html
前端老石人4 小时前
HTML 字符引用完全指南
开发语言·前端·html
matlab_xiaowang4 小时前
Redux 入门:JavaScript 可预测状态管理库
开发语言·javascript·其他·ecmascript
幼儿园技术家5 小时前
前端如何设计权限系统(RBAC / ABAC)?
前端
前端摸鱼匠6 小时前
Vue 3 的v-bind合并行为:讲解v-bind与普通属性合并的规则
前端·javascript·vue.js·前端框架·ecmascript
REDcker6 小时前
浏览器端Web程序性能分析与优化实战 DevTools指标与工程清单
开发语言·前端·javascript·vue·ecmascript·php·js
donecoding8 小时前
一个 sudo 引发的血案:npm 全局包权限错乱彻底修复
前端·node.js·前端工程化
风骏时光牛马8 小时前
Raku正则匹配与数据批量处理实操案例
前端
nbwenren8 小时前
2026实测:Gemini 3 镜像站视觉能力实践——拍照原型图,一键生成 HTML+CSS 代码
前端·css·html
Lee川8 小时前
Prisma 实战指南:像搭积木一样设计古诗词数据库
前端·数据库·后端