App.vue 1.6 KB

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