Sidebar.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
  12. {{ subItem.title }}
  13. </el-menu-item>
  14. </el-submenu>
  15. </template>
  16. <template v-else>
  17. <el-menu-item :index="item.index" :key="item.index">
  18. <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
  19. </el-menu-item>
  20. </template>
  21. </template>
  22. </el-menu>
  23. </div>
  24. </template>
  25. <script>
  26. import bus from '../common/bus';
  27. export default {
  28. data() {
  29. return {
  30. collapse: false,
  31. items: [
  32. {
  33. icon: 'el-icon-setting',
  34. index: 'readme',
  35. title: '自述文件'
  36. },
  37. {
  38. icon: 'el-icon-tickets',
  39. index: '2',
  40. title: '常用表格',
  41. subs: [
  42. {
  43. index: 'table',
  44. title: '基础表格'
  45. },
  46. {
  47. index: 'datasource',
  48. title: 'datasource表格'
  49. }
  50. ]
  51. },
  52. {
  53. icon: 'el-icon-date',
  54. index: '3',
  55. title: '表单相关',
  56. subs: [
  57. {
  58. index: 'form',
  59. title: '基本表单'
  60. },
  61. {
  62. index: 'editor',
  63. title: '富文本编辑器'
  64. },
  65. {
  66. index: 'markdown',
  67. title: 'markdown编辑器'
  68. },
  69. {
  70. index: 'upload',
  71. title: '文件上传'
  72. }
  73. ]
  74. },
  75. {
  76. icon: 'el-icon-star-on',
  77. index: 'charts',
  78. title: 'schart图表'
  79. },
  80. {
  81. icon: 'el-icon-rank',
  82. index: 'drag',
  83. title: '拖拽列表'
  84. },
  85. {
  86. icon: 'el-icon-warning',
  87. index: 'permission',
  88. title: '权限测试'
  89. }
  90. ]
  91. }
  92. },
  93. computed:{
  94. onRoutes(){
  95. return this.$route.path.replace('/','');
  96. }
  97. },
  98. created(){
  99. // 通过 Event Bus 进行组件间通信,来折叠侧边栏
  100. bus.$on('collapse', msg => {
  101. this.collapse = msg;
  102. })
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. .sidebar{
  108. display: block;
  109. position: absolute;
  110. left: 0;
  111. top: 70px;
  112. bottom:0;
  113. }
  114. .sidebar-el-menu:not(.el-menu--collapse){
  115. width: 250px;
  116. }
  117. .sidebar > ul {
  118. height:100%;
  119. }
  120. </style>