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>
相关推荐
不像程序员的程序媛21 分钟前
Nginx日志切分
服务器·前端·nginx
Daniel李华30 分钟前
echarts使用案例
android·javascript·echarts
北原_春希31 分钟前
如何在Vue3项目中引入并使用Echarts图表
前端·javascript·echarts
JY-HPS31 分钟前
echarts天气折线图
javascript·vue.js·echarts
尽意啊32 分钟前
echarts树图动态添加子节点
前端·javascript·echarts
吃面必吃蒜32 分钟前
echarts 极坐标柱状图 如何定义柱子颜色
前端·javascript·echarts
O_oStayPositive33 分钟前
Vue3使用ECharts
前端·javascript·echarts
竹秋…33 分钟前
echarts自定义tooltip中的内容
前端·javascript·echarts
宝贝露.33 分钟前
Axure引入Echarts图无法正常显示问题
前端·javascript·echarts
shmily麻瓜小菜鸡34 分钟前
前端文字转语音
前端