frameView.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <div class="frame" v-loading="loading">
  3. <iframe :src="frameSrc" class="frame-iframe" ref="frameRef" />
  4. </div>
  5. </template>
  6. <script lang="ts" setup>
  7. import { useRoute } from "vue-router";
  8. import { ref, unref, onMounted, nextTick } from "vue";
  9. const loading = ref(false);
  10. const currentRoute = useRoute();
  11. const frameSrc = ref<string>("");
  12. const frameRef = ref<HTMLElement | null>(null);
  13. if (unref(currentRoute.meta)?.frameSrc) {
  14. frameSrc.value = unref(currentRoute.meta)?.frameSrc as string;
  15. }
  16. function hideLoading() {
  17. loading.value = false;
  18. }
  19. function init() {
  20. nextTick(() => {
  21. const iframe = unref(frameRef);
  22. if (!iframe) return;
  23. const _frame = iframe as any;
  24. if (_frame.attachEvent) {
  25. _frame.attachEvent("onload", () => {
  26. hideLoading();
  27. });
  28. } else {
  29. iframe.onload = () => {
  30. hideLoading();
  31. };
  32. }
  33. });
  34. }
  35. onMounted(() => {
  36. loading.value = true;
  37. init();
  38. });
  39. </script>
  40. <style lang="scss" scoped>
  41. .frame {
  42. height: 100vh;
  43. z-index: 998;
  44. .frame-iframe {
  45. width: 100%;
  46. height: 100%;
  47. overflow: hidden;
  48. border: 0;
  49. box-sizing: border-box;
  50. }
  51. }
  52. .main-content {
  53. margin: 0 !important;
  54. }
  55. </style>