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>
相关推荐
yivifu2 小时前
CSS Grid 布局详解(2025最新标准)
前端·css
o***Z4483 小时前
前端性能优化案例
前端
张拭心4 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程
姜太小白4 小时前
【前端】CSS媒体查询响应式设计详解:@media (max-width: 600px) {……}
前端·css·媒体
weixin_411191844 小时前
flutter中WebView的使用及JavaScript桥接的问题记录
javascript·flutter
HIT_Weston4 小时前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu
百***06014 小时前
SpringMVC 请求参数接收
前端·javascript·算法
天外天-亮4 小时前
Vue + excel下载 + 水印
前端·vue.js·excel
起个名字逛街玩4 小时前
前端正在走向“工程系统化”:从页面开发到复杂产品架构的深度进化
前端·架构