侧边菜单的展开和折叠


环境准备: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 小时前
网络请求库——Axios库深度解析
前端·网络·vue.js·北京百思可瑞教育·百思可瑞教育
一朵梨花压海棠go3 小时前
html+js实现表格本地筛选
开发语言·javascript·html·ecmascript
一只小风华~4 小时前
Vue: Class 与 Style 绑定
前端·javascript·vue.js·typescript·前端框架
十碗饭吃不饱5 小时前
net::ERR_EMPTY_RESPONSE
java·javascript·chrome·html5
Zz_waiting.5 小时前
Javaweb - 14.6 - Vue3 数据交互 Axios
开发语言·前端·javascript·vue·axios
切糕师学AI5 小时前
前后端分离架构中,Node.js的底层实现原理与线程池饥饿问题解析
前端·vue.js·node.js
每天吃饭的羊6 小时前
state和ref
前端·javascript·react.js
GEO_YScsn6 小时前
Vite:Next-Gen Frontend Tooling 的高效之道——从原理到实践的性能革命
前端·javascript·css·tensorflow
GISer_Jing6 小时前
滴滴二面(准备二)
前端·javascript·vue·reactjs
摇滚侠6 小时前
Vue3入门到实战,最新版vue3+TypeScript前端开发教程,笔记03
javascript·笔记·typescript