Sidebar.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="sidebar">
  3. <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
  4. text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
  5. <template v-for="item in items">
  6. <template v-if="item.subs">
  7. <el-submenu :index="item.index" :key="item.index">
  8. <template slot="title">
  9. <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
  10. </template>
  11. <template v-for="subItem in item.subs">
  12. <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
  13. <template slot="title">{{ subItem.title }}</template>
  14. <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
  15. {{ threeItem.title }}
  16. </el-menu-item>
  17. </el-submenu>
  18. <el-menu-item v-else :index="subItem.index" :key="subItem.index">
  19. {{ subItem.title }}
  20. </el-menu-item>
  21. </template>
  22. </el-submenu>
  23. </template>
  24. <template v-else>
  25. <el-menu-item :index="item.index" :key="item.index">
  26. <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
  27. </el-menu-item>
  28. </template>
  29. </template>
  30. </el-menu>
  31. </div>
  32. </template>
  33. <script>
  34. import bus from '../common/bus';
  35. export default {
  36. data() {
  37. return {
  38. collapse: false,
  39. items: [
  40. {
  41. icon: 'el-icon-lx-home',
  42. index: 'dashboard',
  43. title: '系统首页'
  44. },
  45. {
  46. icon: 'el-icon-lx-cascades',
  47. index: 'table',
  48. title: '基础表格'
  49. },
  50. {
  51. icon: 'el-icon-lx-copy',
  52. index: 'tabs',
  53. title: 'tab选项卡'
  54. },
  55. {
  56. icon: 'el-icon-lx-calendar',
  57. index: '3',
  58. title: '表单相关',
  59. subs: [
  60. {
  61. index: 'form',
  62. title: '基本表单'
  63. },
  64. {
  65. index: '3-2',
  66. title: '三级菜单',
  67. subs: [
  68. {
  69. index: 'editor',
  70. title: '富文本编辑器'
  71. },
  72. {
  73. index: 'markdown',
  74. title: 'markdown编辑器'
  75. },
  76. ]
  77. },
  78. {
  79. index: 'upload',
  80. title: '文件上传'
  81. }
  82. ]
  83. },
  84. {
  85. icon: 'el-icon-lx-emoji',
  86. index: 'icon',
  87. title: '自定义图标'
  88. },
  89. {
  90. icon: 'el-icon-lx-favor',
  91. index: 'charts',
  92. title: 'schart图表'
  93. },
  94. {
  95. icon: 'el-icon-rank',
  96. index: 'drag',
  97. title: '拖拽列表'
  98. },
  99. {
  100. icon: 'el-icon-lx-warn',
  101. index: '6',
  102. title: '错误处理',
  103. subs: [
  104. {
  105. index: 'permission',
  106. title: '权限测试'
  107. },
  108. {
  109. index: '404',
  110. title: '404页面'
  111. }
  112. ]
  113. }
  114. ]
  115. }
  116. },
  117. computed:{
  118. onRoutes(){
  119. return this.$route.path.replace('/','');
  120. }
  121. },
  122. created(){
  123. // 通过 Event Bus 进行组件间通信,来折叠侧边栏
  124. bus.$on('collapse', msg => {
  125. this.collapse = msg;
  126. })
  127. }
  128. }
  129. </script>
  130. <style scoped>
  131. .sidebar{
  132. display: block;
  133. position: absolute;
  134. left: 0;
  135. top: 70px;
  136. bottom:0;
  137. overflow-y: scroll;
  138. }
  139. .sidebar::-webkit-scrollbar{
  140. width: 0;
  141. }
  142. .sidebar-el-menu:not(.el-menu--collapse){
  143. width: 250px;
  144. }
  145. .sidebar > ul {
  146. height:100%;
  147. }
  148. </style>