menu-item.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div id="menu-item">
  3. <template v-for="(item, index) in menus">
  4. <!-- 没有子菜单情况 -->
  5. <template v-if="item && item.children && item.children <= 0">
  6. <el-menu-item :index="item.route" @click="selectMenu(item.route, item.module)" :key="index">
  7. <i v-if="item.icon" :class="item.icon"></i>
  8. <span v-if="item.title" slot="title">
  9. <!-- <span :style="{ paddingLeft: `${level * 1}px` }">{{ item.title }}</span> -->
  10. {{ item.title }}
  11. </span>
  12. </el-menu-item>
  13. </template>
  14. <template v-else>
  15. <el-submenu :index="item.title || item.route" :key="item.title">
  16. <template slot="title">
  17. <i v-if="item && item.icon" :class="item.icon"></i>
  18. <span v-if="item && item.title">
  19. <!-- <span :style="{ paddingLeft: `${level * 1}px` }">{{ item.title }}</span> -->
  20. {{ item.title }}
  21. </span>
  22. </template>
  23. <menu-item :menus="item.children" :level="level + 1"></menu-item>
  24. </el-submenu>
  25. </template>
  26. </template>
  27. </div>
  28. </template>
  29. <script>
  30. import { mapState, createNamespacedHelpers } from 'vuex';
  31. export default {
  32. name: 'menu-item',
  33. props: {
  34. level: { type: Number, default: 0 },
  35. menus: { type: Array, require: true },
  36. },
  37. components: {},
  38. data: function() {
  39. return {};
  40. },
  41. created() {},
  42. methods: {
  43. selectMenu(path, modules) {
  44. this.$router.push({ path: path });
  45. },
  46. },
  47. computed: {
  48. ...mapState(['user']),
  49. },
  50. };
  51. </script>
  52. <style lang="less" scoped>
  53. .el-submenu .el-menu-item {
  54. min-width: 16rem !important;
  55. // padding-left: 3rem !important;
  56. background-color: #000c17 !important;
  57. &:hover {
  58. color: #fff !important;
  59. }
  60. }
  61. .el-submenu__title i {
  62. font-size: 1rem;
  63. color: rgba(255, 255, 255, 0.65);
  64. }
  65. .el-menu-item,
  66. .el-submenu .el-menu-item {
  67. &.is-active {
  68. background-color: #188fff !important;
  69. color: #fff !important;
  70. }
  71. }
  72. </style>