SideNav.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <el-menu
  3. background-color="#304156"
  4. text-color="#BFCBD9"
  5. active-text-color="#ffffff"
  6. :default-active="activeIndex"
  7. class="nav"
  8. @open="handleMenuOpen"
  9. @close="handleMenuClose"
  10. :collapse="isCollapse"
  11. >
  12. <p class="logo">{{ routeSetting.name }}</p>
  13. <template v-for="r in routes">
  14. <el-menu-item
  15. :key="r.path"
  16. v-if="!r.children"
  17. :data-to="r.path"
  18. :data-name="r.name"
  19. :index="r.path"
  20. @click="handleToPage"
  21. >
  22. <i v-if="r.icon" :class="r.icon"></i>
  23. <span slot="title">{{ r.name }}</span>
  24. </el-menu-item>
  25. <el-submenu v-else :key="r.path" :index="r.path">
  26. <template slot="title">
  27. <i v-if="r.icon" :class="r.icon"></i>
  28. <span slot="title">{{ r.name }}</span>
  29. </template>
  30. <el-menu-item
  31. @click="handleToPage"
  32. :data-to="r.path + c.path"
  33. :data-name="c.name"
  34. :index="r.path + c.path"
  35. v-for="c in r.children"
  36. :key="r.path + c.path"
  37. >
  38. <i v-if="c.icon" :class="c.icon"></i>
  39. <span slot="title">{{ c.name }}</span>
  40. </el-menu-item>
  41. </el-submenu>
  42. </template>
  43. </el-menu>
  44. </template>
  45. <script>
  46. import { routes, routeSetting } from "@/config/routes";
  47. export default {
  48. name: "SideNav",
  49. data: () => {
  50. return {
  51. isCollapse: false,
  52. routes,
  53. routeSetting,
  54. };
  55. },
  56. methods: {
  57. handleMenuOpen() {
  58. },
  59. handleMenuClose() {
  60. },
  61. handleToPage(e) {
  62. const path = e.$el.getAttribute("data-to");
  63. //const name = e.$el.getAttribute("data-name");
  64. //this.$store.commit("addNavTag", { name: name, path: path });
  65. //console.log(path)
  66. if (path !== this.$route.path) {
  67. this.$router.push(path);
  68. }
  69. },
  70. },
  71. computed: {
  72. activeIndex() {
  73. return this.$route.path;
  74. },
  75. },
  76. };
  77. </script>
  78. <style scoped>
  79. .logo {
  80. text-align: center;
  81. color: #ffffff;
  82. }
  83. </style>