subItem.vue 1.6 KB

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