Layout.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <a-layout id="components-layout-demo-responsive">
  3. <a-layout-sider
  4. v-model="collapsed"
  5. theme="dark"
  6. >
  7. <div class="logo"></div>
  8. <a-menu class="menu-item" theme="dark" mode="inline" @click="menuHandle" :default-selected-keys="['menu_1']">
  9. <a-menu-item :key="index" v-for="(menuInfo, index) in menu" :title="menuInfo.title">
  10. <a-icon :type="menuInfo.icon" />
  11. </a-menu-item>
  12. </a-menu>
  13. </a-layout-sider>
  14. <a-layout>
  15. <a-layout-sider
  16. theme="light"
  17. style="background-color: #FAFAFA;"
  18. >
  19. <a-menu class="sub-menu-item" theme="light" mode="inline" v-model="subMenuKey" :default-selected-keys="subMenuKey">
  20. <a-menu-item :key="subIndex" v-for="(menuInfo, subIndex) in subMenu">
  21. <router-link :to="{ path: menuInfo.page }">
  22. <span>{{ menuInfo.title }}</span>
  23. </router-link>
  24. </a-menu-item>
  25. </a-menu>
  26. </a-layout-sider>
  27. <a-layout-content :style="{}">
  28. <div :style="{ padding: '24px', background: '#fff', minHeight: '560px' }">
  29. <router-view />
  30. </div>
  31. </a-layout-content>
  32. </a-layout>
  33. </a-layout>
  34. </template>
  35. <script>
  36. export default {
  37. name: 'Layout',
  38. data() {
  39. return {
  40. collapsed: true,
  41. menu: {
  42. 'menu_1' : {
  43. icon: 'home',
  44. title: ''
  45. },
  46. 'menu_2' : {
  47. icon: 'setting',
  48. title: ''
  49. },
  50. },
  51. menuKey: 'menu_1',
  52. subMenuKey: ['subMenu_1'],
  53. subMenu: {},
  54. subMenuList: {
  55. 'menu_1' : {
  56. 'subMenu_1' : {
  57. title: '首页菜单1',
  58. page: '/testa'
  59. },
  60. 'subMenu_2' : {
  61. title: '首页菜单2',
  62. page: '/testb'
  63. },
  64. },
  65. 'menu_2' : {
  66. 'subMenu_1' : {
  67. title: '设置菜单1',
  68. page: '/testc/testc'
  69. },
  70. 'subMenu_2' : {
  71. title: '设置菜单2',
  72. page: '/testd'
  73. },
  74. },
  75. },
  76. contentPage: ''
  77. };
  78. },
  79. mounted () {
  80. this.menuHandle({key: 'menu_1'})
  81. },
  82. methods: {
  83. menuHandle (item) {
  84. this.subMenu = this.subMenuList[item.key]
  85. this.subMenuKey = ['subMenu_1']
  86. const linkPage = this.subMenu['subMenu_1']['page']
  87. this.$router.push(linkPage)
  88. },
  89. },
  90. };
  91. </script>
  92. <style lang="less" scoped>
  93. // 嵌套
  94. #components-layout-demo-responsive {
  95. .logo {
  96. height: 32px;
  97. background: rgba(139, 137, 137, 0.2);
  98. margin: 16px;
  99. }
  100. .menu-item {
  101. .ant-menu-item {
  102. background-color: #001529;
  103. margin-top: 0px;
  104. margin-bottom: 0px;
  105. }
  106. }
  107. .sub-menu-item {
  108. .ant-menu-item {
  109. margin-top: 0px;
  110. margin-bottom: 0px;
  111. }
  112. .ant-menu-item::after {
  113. border-right: 3px solid #F2F2F2;
  114. }
  115. .ant-menu-item-selected {
  116. background-color:#F2F2F2;
  117. span {
  118. color: #111;
  119. }
  120. }
  121. }
  122. .sub-menu-item.ant-menu {
  123. background: #FAFAFA;
  124. }
  125. .sub-menu-item.ant-menu-inline {
  126. border-right: 0px solid #FAFAFA;
  127. }
  128. }
  129. // #components-layout-demo-responsive .logo {
  130. // height: 32px;
  131. // background: rgba(139, 137, 137, 0.2);
  132. // margin: 16px;
  133. // }
  134. // #components-layout-demo-responsive .menu-item .ant-menu-item {
  135. // background-color: #001529;
  136. // margin-top: 0px;
  137. // margin-bottom: 0px;
  138. // }
  139. // #components-layout-demo-responsive .sub-menu-item .ant-menu-item {
  140. // margin-top: 0px;
  141. // margin-bottom: 0px;
  142. // }
  143. // #components-layout-demo-responsive .sub-menu-item .ant-menu-item::after {
  144. // border-right: 3px solid #F2F2F2;
  145. // }
  146. // #components-layout-demo-responsive .sub-menu-item.ant-menu {
  147. // background: #FAFAFA;
  148. // }
  149. // #components-layout-demo-responsive .sub-menu-item.ant-menu-inline {
  150. // border-right: 0px solid #FAFAFA;
  151. // }
  152. // #components-layout-demo-responsive .sub-menu-item .ant-menu-item-selected {
  153. // background-color:#F2F2F2;
  154. // span {
  155. // color: #111;
  156. // }
  157. // }
  158. </style>