侧边菜单的展开和折叠


环境准备: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>
相关推荐
呆呆的小草2 小时前
Cesium距离测量、角度测量、面积测量
开发语言·前端·javascript
WHOAMI_老猫2 小时前
xss注入遇到转义,html编码绕过了解一哈
javascript·web安全·渗透测试·xss·漏洞原理
一 乐3 小时前
民宿|基于java的民宿推荐系统(源码+数据库+文档)
java·前端·数据库·vue.js·论文·源码
BillKu3 小时前
Vue3 + TypeScript + Element Plus 表格行按钮不触发 row-click 事件、不触发勾选行,只执行按钮的 click 事件
vue.js·elementui·typescript
小前端大牛马3 小时前
react中hook和高阶组件的选型
前端·javascript·vue.js
刺客-Andy3 小时前
React第六十二节 Router中 createStaticRouter 的使用详解
前端·javascript·react.js
秋田君4 小时前
深入理解JavaScript设计模式之策略模式
javascript·设计模式·策略模式
萌萌哒草头将军5 小时前
🚀🚀🚀VSCode 发布 1.101 版本,Copilot 更全能!
前端·vue.js·react.js
菜鸡爱上编程6 小时前
React16,17,18,19更新对比
前端·javascript·reactjs·react
我命由我123456 小时前
VSCode - VSCode 转换英文字母的大小写
开发语言·javascript·ide·vscode·编辑器·html·软件工具