App.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div
  3. class="app-ct"
  4. :class="{ 'sidebar-open': sidebarOpen }"
  5. >
  6. <app-header @sidebar-change="sidebarOpen = !sidebarOpen" />
  7. <div class="app-bd">
  8. <div
  9. class="app-sd-mask"
  10. @click="sidebarOpen = false"
  11. />
  12. <app-aside />
  13. <router-view />
  14. </div>
  15. </div>
  16. </template>
  17. <style lang="scss" src="./assets/scss/demo.scss"></style>
  18. <script>
  19. import AppHeader from './components/AppHeader.vue'
  20. import AppAside from './components/AppAside.vue'
  21. export default {
  22. name: 'App',
  23. components: { AppHeader, AppAside },
  24. data () {
  25. return {
  26. sidebarOpen: false
  27. }
  28. },
  29. watch: {
  30. // 路由切换
  31. $route ($route) {
  32. // 关闭侧边栏
  33. this.sidebarOpen = false
  34. }
  35. }
  36. }
  37. </script>
  38. <style lang="scss" scoped>
  39. $side-width: 200px;
  40. $just-trans: all .2s ease-in-out;
  41. /* 布局 */
  42. .app-ct {
  43. display: flex;
  44. flex-direction: column;
  45. width: 100%;
  46. height: 100%;
  47. .app-sd {
  48. width: $side-width;
  49. transition: $just-trans;
  50. @include screen-mob {
  51. left: -$side-width;
  52. }
  53. }
  54. .app-bd {
  55. flex: 1;
  56. position: relative;
  57. }
  58. }
  59. .sidebar-open {
  60. @include screen-mob {
  61. .app-sd-mask {
  62. display: block;
  63. }
  64. .app-sd {
  65. left: 0;
  66. }
  67. }
  68. }
  69. .app-sd-mask,
  70. .app-sd {
  71. position: absolute;
  72. top: 0;
  73. left: 0;
  74. z-index: 10;
  75. height: 100%;
  76. }
  77. .app-sd-mask {
  78. display: none;
  79. width: 100%;
  80. }
  81. .app-main {
  82. position: absolute;
  83. top: 0;
  84. right: 0;
  85. bottom: 0;
  86. left: $side-width;
  87. height: 100%;
  88. transition: $just-trans;
  89. @include screen-mob {
  90. left: 0;
  91. }
  92. /deep/ .router-tab {
  93. height: 100%;
  94. }
  95. }
  96. </style>