侧边菜单的展开和折叠


环境准备:Vue3+Element-UI Plus

html 复制代码
<script setup>
import {ref} from "vue";

// 是否折叠菜单,默认折叠
const isCollapse = ref(true)

// 退出登录
function logout() {
  alert('退出')
}

// 个人中心
function profile() {
  alert('个人中心')
}
</script>

<template>
  <el-container>
    <el-aside>
      <el-scrollbar>
        <el-menu
            :collapse="isCollapse"
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            default-active="2"
            text-color="#fff"
        >
          <el-sub-menu index="1">
            <template #title>
              <el-icon>
                <location/>
              </el-icon>
              <span>Navigator One</span>
            </template>
            <el-menu-item-group title="Group One">
              <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>item four</template>
              <el-menu-item index="1-4-1">item one</el-menu-item>
            </el-sub-menu>
          </el-sub-menu>
          <el-menu-item index="2">
            <el-icon>
              <Menu/>
            </el-icon>
            <span>Navigator Two</span>
          </el-menu-item>
          <el-menu-item index="3" disabled>
            <el-icon>
              <document/>
            </el-icon>
            <span>Navigator Three</span>
          </el-menu-item>
          <el-menu-item index="4">
            <el-icon>
              <setting/>
            </el-icon>
            <span>Navigator Four</span>
          </el-menu-item>
        </el-menu>
      </el-scrollbar>
    </el-aside>
    <el-container style="height: 100vh;">
      <el-header>
        <el-row align="middle" justify="space-between" style="height: 100%">
          <el-col :span="1" style="cursor: pointer">
            <el-icon v-show="isCollapse" @click="isCollapse=false">
              <Expand/>
            </el-icon>
            <el-icon v-show="!isCollapse" @click="isCollapse=true">
              <Fold/>
            </el-icon>
          </el-col>
          <el-col :span="1">
            <el-dropdown>
              <el-image class="avatar" src="/public/vite.svg"></el-image>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="profile">个人信息</el-dropdown-item>
                  <el-dropdown-item @click="logout" divided>退出</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
        </el-row>
      </el-header>
      <el-main>
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped lang="scss">
.el-container {
  .el-aside {
    height: 100vh;
    width: auto;
    :deep(.el-scrollbar__view ){
      height: 100%;
      .el-menu {
        height: 100%;
        width: 100%;
      }
    }
  }

  .el-container {
    .el-header {
      background-color: #ffffff;

      .avatar {
        border-radius: 50%;
        cursor: pointer;
      }
    }

    .el-main {
      background-color: #efefef;
    }
  }
}
</style>
相关推荐
叼烟扛炮1 小时前
[LangChain] 学习笔记(03):打破失忆症——对话机制与上下文管理
java·前端·javascript·笔记·学习·langchain
卋罖7502 小时前
Razor 视图 + JavaScript + Vue/iView 组件实现的表格自定义列
javascript·vue·iview·razor视图
系统集成-鹰翔17 小时前
ERP图片改名后仍命中识别缓存:缓存键、十分钟到期与调用计数
javascript·经验分享·后端
FlyWIHTSKY19 小时前
vue2和vue3有什么区别,用法上有哪些区别
前端·javascript·vue.js
程序员大阳20 小时前
副队长JavaScript教程(66)-本地存储实战:待办事项网页的开发
javascript·json·实战·待办事项·本地存储·案例
Dream-Y.ocean21 小时前
鸿蒙PC平台逻控 PLC 编辑器适配实战:基于 Electron 壳方案的纯 JavaScript 梯形图编程与仿真引擎开发
javascript·编辑器·harmonyos
前端小D1 天前
JS核心底层
前端·javascript
Dovis(誓平步青云)1 天前
启元 T1 Pro 人机相声搭档:语音-触摸双通道的启元机器人节奏引擎设计
开发语言·前端·javascript·microsoft·交互
ruanno_top1 天前
能点,但 Tab 不到:两个组件把「可操作」做了一半
vue.js
爱吃烧烤的技术渣1 天前
别再手写 CRUD 了:我把 Element Plus 的工作量压缩成一份列 schema
前端·vue.js