diff --git a/src/layout/routerView/iframes.vue b/src/layout/routerView/iframes.vue index 1352a24..328f886 100644 --- a/src/layout/routerView/iframes.vue +++ b/src/layout/routerView/iframes.vue @@ -51,22 +51,26 @@ export default defineComponent({ const getRoutePath = computed(() => { return route.path; }); + // 关闭 iframe loading + const closeIframeLoading = (val: string, item: any) => { + nextTick(() => { + if (!iframeRef.value) return false; + iframeRef.value.forEach((v: any) => { + if (v.dataset.url === val) { + v.onload = () => { + if (item && item.meta.isIframeOpen && item.meta.loading) item.meta.loading = false; + }; + } + }); + }); + }; // 监听路由变化,初始化 iframe 数据,防止多个 iframe 时,切换不生效 watch( () => route.fullPath, (val) => { const item: any = props.list.find((v: any) => v.path === val); if (item && !item.meta.isIframeOpen) item.meta.isIframeOpen = true; - nextTick(() => { - if (!iframeRef.value) return false; - iframeRef.value.forEach((v: any) => { - if (v.dataset.url === val) { - v.onload = () => { - if (item && item.meta.isIframeOpen && item.meta.loading) item.meta.loading = false; - }; - } - }); - }); + closeIframeLoading(val, item); }, { immediate: true, @@ -78,8 +82,10 @@ export default defineComponent({ () => { const item: any = props.list.find((v: any) => v.path === route.path); if (item && item.meta.isIframeOpen) item.meta.isIframeOpen = false; - nextTick(() => { + setTimeout(() => { item.meta.isIframeOpen = true; + item.meta.loading = true; + closeIframeLoading(route.fullPath, item); }); }, {