main.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="mainMenu">
  3. <router-link
  4. :class="{ activeLink: active === index }"
  5. :to="item.child"
  6. v-for="(item, index) in mainList"
  7. :key="'mainMenu' + index"
  8. >{{ item.meta.title }}</router-link
  9. >
  10. </div>
  11. </template>
  12. <script>
  13. import { mapGetters } from "vuex";
  14. export default {
  15. name: "mainMenu",
  16. data() {
  17. return {
  18. active: -1,
  19. list: [],
  20. };
  21. },
  22. computed: {
  23. //组件SIZE设置
  24. ...mapGetters(["mainList"]),
  25. },
  26. watch: {
  27. $route(route) {
  28. if (route.path.startsWith("/redirect/")) {
  29. return;
  30. }
  31. this.getBreadcrumb();
  32. },
  33. },
  34. created() {
  35. this.getBreadcrumb();
  36. },
  37. methods: {
  38. getBreadcrumb() {
  39. let matched = this.$route.matched.filter(
  40. (item) => item.meta && item.meta.title
  41. );
  42. let levelList = matched.filter(
  43. (item) => item.meta && item.meta.title && item.meta.breadcrumb !== false
  44. );
  45. if (levelList[0] && levelList[0].path) {
  46. this.active = this.mainList.findIndex(
  47. (v1) => v1.path === levelList[0].path
  48. );
  49. } else {
  50. this.active = -1;
  51. }
  52. },
  53. },
  54. };
  55. </script>
  56. <style lang="scss" scoped>
  57. .mainMenu {
  58. width: calc(100% - 200px);
  59. padding: 5px 0 0 20px;
  60. display: inline-block;
  61. a {
  62. display: inline-block;
  63. padding: 0 20px;
  64. height: 40px;
  65. font-size: 15px;
  66. line-height: 40px;
  67. color: #232323;
  68. font-weight:normal;
  69. &.activeLink {
  70. color: #63cbe7;
  71. font-weight: bold;
  72. }
  73. }
  74. }
  75. </style>