ElAside.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="el-aside">
  3. <slot name="prefix" />
  4. <el-menu
  5. default-active="2"
  6. class="el-menu-vertical-demo"
  7. background-color="#545c64"
  8. text-color="#fff"
  9. active-text-color="#ffd04b"
  10. >
  11. <template v-for="menu in menus">
  12. <el-submenu v-if="menu.items" :key="menu.index" :index="menu.index">
  13. <template slot="title"><i :class="getIcon(menu.icon)" />{{ menu.label }}</template>
  14. <el-menu-item
  15. v-for="item in menu.items"
  16. :key="item.index"
  17. :index="item.index"
  18. @click="send(item)"
  19. >
  20. <i :class="getIcon(item.icon)" />{{ item.label }}
  21. </el-menu-item>
  22. </el-submenu>
  23. <el-menu-item v-else :key="menu.index" :index="menu.index" @click="send(menu)">
  24. <i :class="getIcon(menu.icon)" />{{ menu.label }}
  25. </el-menu-item>
  26. </template>
  27. </el-menu>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. props: ['menus'],
  33. methods: {
  34. send(item) {
  35. this.$emit('redirect', item)
  36. },
  37. getIcon(icon = 'el-icon-menu') {
  38. return icon
  39. }
  40. }
  41. }
  42. </script>
  43. <style scoped>
  44. /*去掉菜单最右边的白框,个人习惯*/
  45. .el-menu {
  46. border-right: 0;
  47. text-align: left;
  48. }
  49. .el-aside {
  50. background-color: #545c64;
  51. color: #333;
  52. text-align: center;
  53. }
  54. </style>