当前位置: 首页 > backend >正文

系统网站首页三种常见布局vue+elementui

  1. 左中右菜单布局
    <template><el-container><el-menu  class="el-menu-vertical-demo" style="width: 80px; height: 100vh;"background-color="#545c64"text-color="#fff"active-text-color="#ffd04b"@select="handleSelect" @open="handleOpen" @close="handleClose" :collapse="isCollapse"><el-menu-item :index="item.path" :key="item.path" v-for="item in sidebarRouters" v-if="item.meta" ><i class="el-icon-menu"><div style="font-size: 14px"><y>{{ item.meta.title.substring(0, 2) }}</y></div></i></el-menu-item></el-menu><el-menu style="width: 200px; height: 100vh;"class="el-menu-vertical-demo"background-color="#545c64"text-color="#fff"routeractive-text-color="#ffd04b"><el-menu-item  :index="item.path" :key="item.path" v-for="(item , index) in menuChildArr"><i class="el-icon-menu"></i><span >{{item.name}}</span></el-menu-item></el-menu><div class="scroll-box"><el-main><router-view></router-view></el-main></div></el-container></template><style>
    .el-menu-vertical-demo:not(.el-menu--collapse) {width: 200px;min-height: 400px;
    }.scroll-box {width: 100%;height: 100vh; /* 占据屏幕高度的 50% */overflow-y: auto; /* 垂直滚动 */box-sizing: border-box;
    }</style><script>
    import store from "@/store";export default {data() {return {sidebarRouters: store.getters.sidebarRouters,countIndex: 0,menuChildMap:{},menuChildArr:  [{name: '用户管理',path: '/system/user'},{name: '角色管理',path: '/system/role'}],isCollapse: true};},methods: {handleOpen(key, keyPath) {},handleSelect(key, keyPath){console.log("AAAAAAA="+ keyPath);console.log(key, keyPath);this.countIndex++;this.menuChildArr=[];let sidebarRouters = this.sidebarRouters;for (let i = 0; i < sidebarRouters.length; i++) {let item = sidebarRouters[i];if (item.meta && item.path==keyPath) {let title = item.meta.title;let children = item.children;for (let j = 0; j < children.length; j++) {let child = children[j];console.log("PPPPP:"+item.path+'/'+child.path);this.menuChildArr.push({name:child.meta.title, path:item.path+'/'+child.path});}}}console.log(JSON.stringify(this.menuChildArr));},handleClose(key, keyPath) {console.log(key, keyPath);}}
    }
    </script>
    

  2. 左右菜单布局
    <template><el-container><el-header style="background-color:#545c64;color: #fff;height: 7vh;"><h1>TMS运输管理系统</h1></el-header><el-container><div class="menu-container"><el-menu:default-active="activeIndex2"class="custom-menu"mode="vertical"@select="handleSelect"background-color="#545c64"text-color="#fff"routeractive-text-color="#ffd04b"><el-submenu  style="background-color: #545c64;" :index="item.path" :key="item.path" v-for="item in sidebarRouters" v-if="item.meta"><template slot="title" style="background-color: #545c64;">{{ item.meta.title }}</template><el-menu-item   style="background-color: #545c64;" :key="child.path" :index="item.path+'/'+child.path" v-for="child in item.children" v-if="child.meta" >{{ child.meta.title }}</el-menu-item></el-submenu><!--<el-menu-item index="/bar" >消息中心</el-menu-item><el-menu-item index="/foo" >消息中心2</el-menu-item><el-menu-item index=""><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>--></el-menu></div><div class="scroll-box"><!-- 路由出口 --><!-- 路由匹配到的组件将渲染在这里 --><el-tagstyle="margin: 5px;":key="tag"v-for="(tag ,index) in dynamicTags"closable:disable-transitions="false":effect="tag.effect"@click="handleClick(tag)"@close="handleClose(tag)"><router-link :to="tag.path"> {{tag.name}} </router-link></el-tag><router-view></router-view></div></el-container></el-container></template><script>import {mapState} from "vuex";
    import store from '@/store'
    export default {name: 'Layout',data() {return {effectValue:'plain',dynamicTags: [{name:'首页',path:'/',effect:'plain'}],activeIndex2: '0',menuIndexName:{'/system/user':'用户管理', '/system/role':'角色管理',  '/system/menu':'菜单管理',  '/system/dept':'部门管理', '/system/dict':'字典管理', '/system/post':'岗位管理','/system/job':'任务管理', '/system/config':'参数管理', '/system/notice':'通知公告', '/system/logininfor':'登录日志', '/system/operlog':'操作日志'},sidebarRouters: store.getters.sidebarRouters};},methods: {handleSelect(key, keyPath) {//console.log(JSON.stringify(store.getters.sidebarRouters))console.log(key, keyPath);let menuIndexName1 = new Map();let sidebarRouters = this.sidebarRouters;console.log("PPPPPFull111:"+JSON.stringify(sidebarRouters));for (let i = 0; i < sidebarRouters.length; i++) {let item = sidebarRouters[i];if (item.meta) {let title = item.meta.title;let children = item.children;for (let j = 0; j < children.length; j++) {let child = children[j];let pathFull = item.path+'/'+child.path;let titleChild = child.meta.title;console.log("PPPPP:"+pathFull,titleChild);menuIndexName1.set(pathFull,titleChild); // ={item.path+'/'+child.path:child.meta.title};}}}console.log("PPPPPFull:"+JSON.stringify(menuIndexName1));//置灰其它菜单按钮tagthis.dynamicTags.forEach(item => {item.effect='plain';});//激活当前菜单按钮taglet menuName = menuIndexName1.get(keyPath[1]);let menuNameJson={name:menuName, path:keyPath[1],effect:'dark'};this.dynamicTags.push(menuNameJson);//this.$router.push({path: keyPath});},handleClose(tag) {this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);//激活后一个按钮tagif(this.dynamicTags.length>1){let dynamicTagsCur = this.dynamicTags[this.dynamicTags.length-1];dynamicTagsCur.effect='dark';let returnUrl = dynamicTagsCur.path;//刷新路由//this.$router.replace(decodeURIComponent(returnUrl || '/'));this.$router.push({path: returnUrl,query: {...this.$route.query,timestamp: Date.now()}});}},handleClick(tag){//置灰其它菜单按钮tagthis.dynamicTags.forEach(item => {item.effect='plain';});//单击事件激活当前按钮tag.effect='dark';}}
    };</script><style scoped lang="scss">
    .el-tag + .el-tag {margin: 5px;
    }
    .menu-container {display: flex;width:  15vw;height: 93vh; /* 占据整个视口高度 */
    }.custom-menu {flex: 1;height: 100%; /* 高度自适应父容器 */
    }
    .scroll-box {width:  100%;height: 93vh; /* 占据屏幕高度的 50% */overflow-y: auto; /* 垂直滚动 */box-sizing: border-box;
    }</style>
    

  3. 上下菜单布局

 

<template><div id="app"><el-menu:default-active="activeIndex2"class="el-menu-demo"mode="horizontal"@select="handleSelect"background-color="#545c64"text-color="#fff"routeractive-text-color="#ffd04b"><el-submenu :index="item.path" :key="item.path" v-for="item in sidebarRouters" v-if="item.meta"><template slot="title" >{{ item.meta.title }}</template><el-menu-item  :key="child.path" :index="item.path+'/'+child.path" v-for="child in item.children" v-if="child.meta" >{{ child.meta.title }}</el-menu-item></el-submenu><!--<el-menu-item index="/bar" >消息中心</el-menu-item><el-menu-item index="/foo" >消息中心2</el-menu-item><el-menu-item index=""><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>--></el-menu><!-- 路由出口 --><!-- 路由匹配到的组件将渲染在这里 --><el-tag:key="tag"v-for="(tag ,index) in dynamicTags"closable:disable-transitions="false":effect="tag.effect"@click="handleClick(tag)"@close="handleClose(tag)"><router-link :to="tag.path"> {{tag.name}} </router-link></el-tag><router-view></router-view></div></template><script>import {mapState} from "vuex";
import store from '@/store'
export default {name: 'Layout',data() {return {effectValue:'plain',dynamicTags: [{name:'首页',path:'/',effect:'plain'}],activeIndex2: '0',menuIndexName:{'/system/user':'用户管理', '/system/role':'角色管理',  '/system/menu':'菜单管理',  '/system/dept':'部门管理', '/system/dict':'字典管理', '/system/post':'岗位管理','/system/job':'任务管理', '/system/config':'参数管理', '/system/notice':'通知公告', '/system/logininfor':'登录日志', '/system/operlog':'操作日志'},sidebarRouters: store.getters.sidebarRouters};},methods: {handleSelect(key, keyPath) {//console.log(JSON.stringify(store.getters.sidebarRouters))console.log(key, keyPath);let menuIndexName1 = new Map();let sidebarRouters = this.sidebarRouters;console.log("PPPPPFull111:"+JSON.stringify(sidebarRouters));for (let i = 0; i < sidebarRouters.length; i++) {let item = sidebarRouters[i];if (item.meta) {let title = item.meta.title;let children = item.children;for (let j = 0; j < children.length; j++) {let child = children[j];let pathFull = item.path+'/'+child.path;let titleChild = child.meta.title;console.log("PPPPP:"+pathFull,titleChild);menuIndexName1.set(pathFull,titleChild); // ={item.path+'/'+child.path:child.meta.title};}}}console.log("PPPPPFull:"+JSON.stringify(menuIndexName1));//置灰其它菜单按钮tagthis.dynamicTags.forEach(item => {item.effect='plain';});//激活当前菜单按钮taglet menuName = menuIndexName1.get(keyPath[1]);let menuNameJson={name:menuName, path:keyPath[1],effect:'dark'};this.dynamicTags.push(menuNameJson);//this.$router.push({path: keyPath});},handleClose(tag) {this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);//激活后一个按钮tagif(this.dynamicTags.length>1){let dynamicTagsCur = this.dynamicTags[this.dynamicTags.length-1];dynamicTagsCur.effect='dark';let returnUrl = dynamicTagsCur.path;//刷新路由//this.$router.replace(decodeURIComponent(returnUrl || '/'));this.$router.push({path: returnUrl,query: {...this.$route.query,timestamp: Date.now()}});}},handleClick(tag){//置灰其它菜单按钮tagthis.dynamicTags.forEach(item => {item.effect='plain';});//单击事件激活当前按钮tag.effect='dark';}}
};</script><style scoped lang="scss">
.el-tag {margin: 5px;
}
</style>

http://www.xdnf.cn/news/13285.html

相关文章:

  • 【Element Plus】Menu组件:url访问页面时高亮对应菜单栏
  • 板凳-------Mysql cookbook学习 (十--4)
  • 小程序动画性能提升指南:CSS硬件加速与JavaScript动画框架对比
  • CentOS下的运维监控Grafana部署
  • 【HarmonyOS Next之旅】DevEco Studio使用指南(三十二) -> 构建系统生命周期
  • okhttp 实现长连接的完整方案
  • OpenLayers 获取地图状态
  • Docker 安装教程(CentOS 系统)纯新手可入门
  • wordpress后台更新后 前端没变化的解决方法
  • Java异步编程之消息队列疑难问题拆解
  • 2506C++,C++的时间库
  • 搭建本地瓦片地图服务器的完整指南
  • 脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)
  • SCAU期末笔记 - 数据分析与数据挖掘题库解析
  • 使用 ML.NET Model Builder 训练机器学习模型进行预测性维护
  • 60天python训练计划----day50
  • 连锁超市冷库节能解决方案:如何实现超市降本增效
  • spring中的ImportSelector接口详解
  • 《高等数学》(同济大学·第7版)第四章第一节不定积分的概念与性质
  • 微软PowerBI考试 PL300-在 Power BI 中设计语义模型 【附练习数据】
  • C++11列表初始化:从入门到精通
  • Python学习(8) ----- Python的类与对象
  • 用 Rust 重写 Linux 内核模块实战:迈向安全内核的新篇章
  • LangChain 中的文档加载器(Loader)与文本切分器(Splitter)详解《二》
  • OpenGL-什么是软OpenGL/软渲染/软光栅?
  • 【求出100~500之间所有每位数的乘积大于每位数的和的数。】2022-4-16
  • c语言(持续更新)
  • 第三章支线四 ·事件风暴 · 时序与响应的协奏
  • LangGraph 深度解析:下一代AI应用编排引擎
  • 五大主流多智能体框架分析