iframe-page.vue 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <iframe :isPage="true" :src="iframeConfig.path" @load="onLoad" class="fw fh" ref="iframe" v-if="iframeConfig.is"></iframe>
  3. </template>
  4. <script setup lang="ts">
  5. import { computed, getCurrentInstance, ref, watch, nextTick } from "vue";
  6. const { proxy } = getCurrentInstance() as any;
  7. const iframe = ref(proxy.$refs.iframe) as any;
  8. const iframeConfig = computed(() => {
  9. return {
  10. is: !!proxy.$route.query.redirect,
  11. path: proxy.$route.query.redirect,
  12. };
  13. });
  14. const emits = defineEmits(["update:loading"]);
  15. watch(
  16. () => iframeConfig.value.path,
  17. () => {
  18. emits("update:loading", iframeConfig.value.is);
  19. nextTick(() => {
  20. if (iframe.value) {
  21. const ifrmaeWindow = iframe.value.contentWindow.window;
  22. if (ifrmaeWindow.onload) {
  23. emits("update:loading", false);
  24. } else {
  25. ifrmaeWindow.onload = () => {
  26. emits("update:loading", false);
  27. };
  28. }
  29. }
  30. });
  31. },
  32. {
  33. deep: true,
  34. }
  35. );
  36. </script>