vue之element-ui侧边栏收缩
vue之element-uiadmin 侧边栏收缩参考 element ui文档自己写了一下,新手勿喷!!!<!DOCTYPE html><html><head><meta charset="UTF-8"><!-- 引入样式 --><link rel="stylesheet" href="https://unpkg.com/elem
·
vue之element-ui admin 侧边栏收缩
参考 element ui 文档自己写了一下,新手勿喷!!!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<style>
* {
padding: 0;
margin: 0;
}
.el-menu {
border: none;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
width: 200px;
min-height: 400px;
}
.el-header,
.el-footer {
background-color: rgb(255, 255, 255);
color: #333;
line-height: 60px;
padding: 0 !important;
}
.el-header i {
font-size: 24px;
}
.el-aside {
background-color: rgb(61, 61, 61);
color: #333;
text-align: center;
line-height: 200px;
}
.el-main {
background-color: #f0f2f5;
color: #333;
text-align: center;
line-height: 160px;
}
body>.el-container {
margin-bottom: 40px;
}
.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
line-height: 260px;
}
.el-container:nth-child(7) .el-aside {
line-height: 320px;
}
.icons {
width: 25px;
height: 60px;
padding: 0 20px;
text-align: center
}
.icons:hover {
background: rgb(248, 248, 248);
transition: 1s;
cursor: pointer;
}
</style>
<body>
<div id="app">
<el-container :style="{height: screenHeight + 'px' }">
<el-menu background-color="#304156" text-color="#bfcbd9" active-text-color="#409eff" default-active="1"
class="el-menu-vertical-demo" @close="handleClose" :collapse="isCollapse">
<el-menu-item index="1">
<i class="el-icon-menu"></i>
<span slot="title">导航一</span>
</el-menu-item>
<el-submenu index="2">
<template slot="title">
<i class="el-icon-location"></i>
<span slot="title" >导航二</span>
</template>
<el-menu-item-group>
<span slot="title">分组一</span>
<el-menu-item index="3-1">选项1</el-menu-item>
<el-menu-item index="1-2">选项2</el-menu-item>
</el-menu-item-group>
<el-menu-item-group title="分组2">
<el-menu-item index="1-3">选项3</el-menu-item>
</el-menu-item-group>
<el-submenu index="1-4">
<span slot="title">选项4</span>
<el-menu-item index="1-4-1">选项1</el-menu-item>
</el-submenu>
</el-submenu>
<el-menu-item index="3">
<i class="el-icon-menu"></i>
<span slot="title">导航三</span>
</el-menu-item>
<el-menu-item index="4">
<i class="el-icon-document"></i>
<span slot="title">导航四</span>
</el-menu-item>
<el-menu-item index="5">
<i class="el-icon-setting"></i>
<span slot="title">导航五</span>
</el-menu-item>
</el-menu>
<el-container>
<el-header>
<div class="icons" @click="toggleCollapse">
<i class="el-icon-s-unfold" v-if="isCollapse"></i>
<i class="el-icon-s-fold"></i>
</div>
</el-header>
<el-main>
</el-main>
</el-container>
</el-container>
</div>
</body>
<!-- 先引入 Vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
isCollapse: true,
screenHeight: window.innerHeight,
};
},
methods: {
toggleCollapse() {
this.isCollapse = !this.isCollapse
},
handleClose() {
},
},
mounted() {
const that = this
window.onresize = () => {
return (() => {
window.screenWidth = document.body.clientWidth
that.screenWidth = window.screenWidth
})()
}
}
})
</script>
</html>
更多推荐
已为社区贡献1条内容
所有评论(0)