当前位置:   article > 正文

vue + element ui 实现侧边栏导航栏折叠收起_element ui 侧边栏菜单

element ui 侧边栏菜单

首页布局如下

要求点击按钮,将侧边栏收缩,

通过 row 和 col 组件,并通过 col 组件的 span 属性我们就可以自由地组合布局。

折叠前

折叠后

  1. <template>
  2. <div class="app-layout" :class="{ collapse: app.isFold }">
  3. <div class="app-layout__mask" @click="app.fold(true)"></div>
  4. <div class="app-layout__left" style="margin-right: 20px;">
  5. <slider />
  6. </div>
  7. <div class="app-layout__right">
  8. <topbar />
  9. <process />
  10. <views />
  11. </div>
  12. </div>
  13. </template>
  14. <script lang="ts" name="app-layout" setup>
  15. import Topbar from "./components/topbar.vue";
  16. import Slider from "./components/slider.vue";
  17. import process from "./components/process.vue";
  18. import Views from "./components/views.vue";
  19. import { useBase } from "/$/base";
  20. const { app } = useBase();
  21. </script>
  22. <style lang="scss" scoped>
  23. .app-layout {
  24. display: flex;
  25. background-color: #f7f7f7;
  26. height: 100%;
  27. width: 100%;
  28. overflow: hidden;
  29. &__left {
  30. overflow: hidden;
  31. height: 100%;
  32. width: 255px;
  33. transition: left 0.2s;
  34. }
  35. &__right {
  36. display: flex;
  37. flex-direction: column;
  38. height: 100%;
  39. width: calc(100% - 255px);
  40. }
  41. &__mask {
  42. position: fixed;
  43. left: 0;
  44. top: 0;
  45. background-color: rgba(0, 0, 0, 0.5);
  46. height: 100%;
  47. width: 100%;
  48. z-index: 999;
  49. }
  50. @media only screen and (max-width: 768px) {
  51. .app-layout__left {
  52. position: absolute;
  53. left: 0;
  54. z-index: 9999;
  55. transition:
  56. transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1),
  57. box-shadow 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
  58. }
  59. .app-layout__right {
  60. width: 100%;
  61. }
  62. &.collapse {
  63. .app-layout__left {
  64. transform: translateX(-100%);
  65. }
  66. .app-layout__mask {
  67. display: none;
  68. }
  69. }
  70. }
  71. @media only screen and (min-width: 768px) {
  72. .app-layout__left,
  73. .app-layout__right {
  74. transition: width 0.2s ease-in-out;
  75. }
  76. .app-layout__mask {
  77. display: none;
  78. }
  79. &.collapse {
  80. .app-layout__left {
  81. width: 64px;
  82. }
  83. .app-layout__right {
  84. width: calc(100% - 64px);
  85. }
  86. }
  87. }
  88. }
  89. </style>

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

闽ICP备14008679号