AppSubMenu.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <a-sub-menu class="nav-item" :key="menus.path">
  3. <template #title>
  4. <span
  5. ><component :is="menus.icon" /><span>{{ menus.meta.title }}</span></span
  6. >
  7. </template>
  8. <template v-for="child in menus.children">
  9. <template v-if="child.children">
  10. <app-sub-menu
  11. :menus="child"
  12. :parent-path="formatRoutes(child.path, parentPath)"
  13. :key="formatRoutes(child.path, parentPath)"
  14. />
  15. </template>
  16. <template v-else>
  17. <router-link
  18. :key="formatRoutes(child.path, parentPath)"
  19. :to="formatRoutes(child.path, parentPath)"
  20. custom
  21. v-slot="{ navigate }"
  22. >
  23. <a-menu-item>
  24. <p @click.stop="navigate">{{ child.meta.title }}</p>
  25. </a-menu-item>
  26. </router-link>
  27. </template>
  28. </template>
  29. </a-sub-menu>
  30. </template>
  31. <script lang="ts">
  32. import { defineComponent } from "vue";
  33. import { pathResolve } from "@/helper";
  34. import {
  35. DesktopOutlined,
  36. PayCircleOutlined,
  37. ProjectOutlined,
  38. } from "@ant-design/icons-vue";
  39. const AppSubMenu = defineComponent({
  40. name: "AppSubMenu",
  41. components: {
  42. DesktopOutlined,
  43. PayCircleOutlined,
  44. ProjectOutlined,
  45. },
  46. props: {
  47. menus: {
  48. type: Object,
  49. default: () => [],
  50. },
  51. parentPath: String,
  52. },
  53. setup(props) {
  54. const formatRoutes = (path: string, base: string = "/") =>
  55. pathResolve(path, base);
  56. return {
  57. formatRoutes,
  58. };
  59. },
  60. });
  61. export default AppSubMenu;
  62. </script>