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>
相关推荐
一 乐11 小时前
婚纱摄影网站|基于ssm + vue婚纱摄影网站系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端
C_心欲无痕11 小时前
ts - tsconfig.json配置讲解
linux·前端·ubuntu·typescript·json
清沫12 小时前
Claude Skills:Agent 能力扩展的新范式
前端·ai编程
yinuo12 小时前
前端跨页面通信终极指南:方案拆解、对比分析
前端
北辰alk12 小时前
Vue 模板引擎深度解析:基于 HTML 的声明式渲染
vue.js
北辰alk13 小时前
Vue 自定义指令完全指南:定义与应用场景详解
vue.js
yinuo13 小时前
前端跨页面通讯终极指南⑨:IndexedDB 用法全解析
前端
北辰alk13 小时前
Vue 动态路由完全指南:定义与参数获取详解
vue.js
北辰alk13 小时前
Vue Router 完全指南:作用与组件详解
vue.js
北辰alk13 小时前
Vue 中使用 this 的完整指南与注意事项
vue.js