当前位置:   article > 正文

vue3+element plus 实现管理系统布局样式_import {document,menu as iconmenu,location,setting

import {document,menu as iconmenu,location,setting} from '@element-plus/icon

先看效果

  • 未设置样式之前:布局没有充满整个页面,而且布局高度会随着左边菜单内容的展开而变化

  • 设置样式后:布局充满整个页面,左边菜单内容展开后也不会影响布局高度,左边菜单内容超出页面高度时会自动添加滚动条

 项目结构目录:

 

设置样式之前代码: 

App.vue

  1. <template>
  2. <Home/>
  3. </template>
  4. <script>
  5. import Home from './components/Home.vue'
  6. export default {
  7. name: 'App',
  8. components: {
  9. Home
  10. }
  11. }
  12. </script>
  13. <style>
  14. @import './assets/css/reset.css';
  15. #app {
  16. font-family: Avenir, Helvetica, Arial, sans-serif;
  17. -webkit-font-smoothing: antialiased;
  18. -moz-osx-font-smoothing: grayscale;
  19. text-align: center;
  20. color: #2c3e50;
  21. }
  22. </style>

 Home.vue   

  1. <template>
  2. <div class="home">
  3. <el-container>
  4. <el-header><Header/></el-header>
  5. <el-container class="content">
  6. <Menu/>
  7. <el-container>
  8. <el-main>Main</el-main>
  9. <el-footer><Footer/></el-footer>
  10. </el-container>
  11. </el-container>
  12. </el-container>
  13. </div>
  14. </template>
  15. <script setup>
  16. import Header from '../components/common/Header.vue'
  17. import Menu from '../components/common/Menu.vue'
  18. import Footer from '../components/common/Footer.vue'
  19. </script>
  20. <style scoped lang="less">
  21. .home{
  22. .el-container{
  23. .el-header{
  24. background-color: #CCCCFF;
  25. }
  26. .el-footer{
  27. background-color: #CCFFFF;
  28. }
  29. .el-main{
  30. background-color: #FFCCCC;
  31. }
  32. }
  33. }
  34. </style>

代码来源于element plus中Container 布局容器

Menu.vue

  1. <template>
  2. <div class="menu">
  3. <el-aside width="200px">
  4. <el-menu
  5. active-text-color="#ffd04b"
  6. background-color="#66CCCC"
  7. class="el-menu-vertical-demo"
  8. default-active="2"
  9. text-color="#fff"
  10. @open="handleOpen"
  11. @close="handleClose"
  12. >
  13. <el-sub-menu index="1">
  14. <template #title>
  15. <el-icon><location /></el-icon>
  16. <span>Navigator One</span>
  17. </template>
  18. <el-menu-item-group title="Group One">
  19. <el-menu-item index="1-1">item one</el-menu-item>
  20. <el-menu-item index="1-2">item two</el-menu-item>
  21. </el-menu-item-group>
  22. <el-menu-item-group title="Group Two">
  23. <el-menu-item index="1-3">item three</el-menu-item>
  24. </el-menu-item-group>
  25. <el-sub-menu index="1-4">
  26. <template #title>item four</template>
  27. <el-menu-item index="1-4-1">item one</el-menu-item>
  28. </el-sub-menu>
  29. </el-sub-menu>
  30. <el-menu-item index="2">
  31. <el-icon><icon-menu /></el-icon>
  32. <span>Navigator Two</span>
  33. </el-menu-item>
  34. <el-menu-item index="3" disabled>
  35. <el-icon><document /></el-icon>
  36. <span>Navigator Three</span>
  37. </el-menu-item>
  38. <el-menu-item index="4">
  39. <el-icon><setting /></el-icon>
  40. <span>Navigator Four</span>
  41. </el-menu-item>
  42. <el-sub-menu index="5">
  43. <template #title>
  44. <el-icon><location /></el-icon>
  45. <span>Navigator One</span>
  46. </template>
  47. <el-menu-item-group title="Group One">
  48. <el-menu-item index="1-1">item one</el-menu-item>
  49. <el-menu-item index="1-2">item two</el-menu-item>
  50. </el-menu-item-group>
  51. <el-menu-item-group title="Group Two">
  52. <el-menu-item index="1-3">item three</el-menu-item>
  53. </el-menu-item-group>
  54. <el-sub-menu index="1-4">
  55. <template #title>item four</template>
  56. <el-menu-item index="1-4-1">item one</el-menu-item>
  57. </el-sub-menu>
  58. </el-sub-menu>
  59. </el-menu>
  60. </el-aside>
  61. </div>
  62. </template>
  63. <script setup>
  64. import {
  65. Document,
  66. Menu as IconMenu,
  67. Location,
  68. Setting,
  69. } from '@element-plus/icons-vue'
  70. const handleOpen = (key, keyPath) => {
  71. console.log(key, keyPath)
  72. }
  73. const handleClose = (key, keyPath) => {
  74. console.log(key, keyPath)
  75. }
  76. </script>
  77. <style lang="less" scoped>
  78. </style>

代码来源于element plus中Menu 菜单

 设置样式:

分别在Home.vue和Menu.vue中添加以下样式即可

Home.vue

  1. <style scoped lang="less">
  2. .home{
  3. .el-container{
  4. // 新加的样式 实现绝对定位
  5. .content{
  6. position: absolute;
  7. top:60px;
  8. bottom: 0;
  9. width: 100%;
  10. }
  11. .el-header{
  12. background-color: #CCCCFF;
  13. }
  14. .el-footer{
  15. background-color: #CCFFFF;
  16. }
  17. .el-main{
  18. background-color: #FFCCCC;
  19. }
  20. }
  21. }
  22. </style>

Menu.vue

  1. <style lang="less" scoped>
  2. .menu{
  3. .el-aside{
  4. height: 100%;
  5. .el-menu{
  6. height: 100%;
  7. }
  8. }
  9. }
  10. </style>

注:若只添加了Home.vue样式则会出现以下效果,menu没有充满页面

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/542605
推荐阅读
相关标签
  

闽ICP备14008679号