subItem.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <template v-for="val in chils">
  3. <el-sub-menu :index="val.path" :key="val.path" v-if="val.children && val.children.length > 0">
  4. <template #title>
  5. <SvgIcon :name="val.meta.icon" />
  6. <span>{{ $t(val.meta.title) }}</span>
  7. </template>
  8. <sub-item :chil="val.children" />
  9. </el-sub-menu>
  10. <template v-else>
  11. <el-menu-item :index="val.path" :key="val.path">
  12. <template v-if="!val.meta.isLink || (val.meta.isLink && val.meta.isIframe)">
  13. <SvgIcon :name="val.meta.icon" />
  14. <span>{{ $t(val.meta.title) }}</span>
  15. </template>
  16. <template v-else>
  17. <a class="w100" @click.prevent="onALinkClick(val)">
  18. <SvgIcon :name="val.meta.icon" />
  19. {{ $t(val.meta.title) }}
  20. </a>
  21. </template>
  22. </el-menu-item>
  23. </template>
  24. </template>
  25. </template>
  26. <script setup lang="ts" name="navMenuSubItem">
  27. import { computed } from 'vue';
  28. import { RouteRecordRaw } from 'vue-router';
  29. import other from '/@/utils/other';
  30. // 定义父组件传过来的值
  31. const props = defineProps({
  32. // 菜单列表
  33. chil: {
  34. type: Array<RouteRecordRaw>,
  35. default: () => [],
  36. },
  37. });
  38. // 获取父级菜单数据
  39. const chils = computed(() => {
  40. return <RouteItems>props.chil;
  41. });
  42. // 打开外部链接
  43. const onALinkClick = (val: RouteItem) => {
  44. other.handleOpenLink(val);
  45. };
  46. </script>