Iframe.vue 982 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div class="iframe-container" v-loading="isLoading">
  3. <iframe
  4. ref="iframeRef"
  5. :src="iframeUrl"
  6. frameborder="0"
  7. class="iframe-content"
  8. @load="handleIframeLoad"
  9. ></iframe>
  10. </div>
  11. </template>
  12. <script setup lang="ts">
  13. import { getIframeRoutes } from '@/router/utils/menuToRouter'
  14. const route = useRoute()
  15. const isLoading = ref(true)
  16. const iframeUrl = ref('')
  17. const iframeRef = ref<HTMLIFrameElement | null>(null)
  18. onMounted(() => {
  19. const iframeRoute = getIframeRoutes().find((item: any) => item.path === route.path)
  20. if (iframeRoute?.meta) {
  21. iframeUrl.value = iframeRoute.meta.link || ''
  22. }
  23. })
  24. const handleIframeLoad = () => {
  25. isLoading.value = false
  26. }
  27. </script>
  28. <style scoped>
  29. .iframe-container {
  30. box-sizing: border-box;
  31. width: 100%;
  32. height: 100%;
  33. }
  34. .iframe-content {
  35. width: 100%;
  36. height: 100%;
  37. min-height: calc(100vh - 120px);
  38. border: none;
  39. }
  40. </style>