From 4f2bf7549c1e81940cff19074e0b690ced9e8596 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 4 Aug 2025 06:02:22 +0800 Subject: [PATCH] no message --- .../assets/js/components/MicroApps/iframe.vue | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/resources/assets/js/components/MicroApps/iframe.vue b/resources/assets/js/components/MicroApps/iframe.vue index 0a4fffe89..2359e2dc1 100644 --- a/resources/assets/js/components/MicroApps/iframe.vue +++ b/resources/assets/js/components/MicroApps/iframe.vue @@ -80,15 +80,14 @@ export default { this.boundHandleLoad = this.handleLoad.bind(this); this.boundHandleError = this.handleError.bind(this); - this.injectMicroApp(); window.addEventListener('message', this.boundHandleMessage); this.$refs.iframe.addEventListener('load', this.boundHandleLoad); this.$refs.iframe.addEventListener('error', this.boundHandleError); + + this.injectMicroApp(); }, beforeDestroy() { - this.cleanupMicroApp(); - // 正确移除事件监听器 if (this.boundHandleMessage) { window.removeEventListener('message', this.boundHandleMessage); @@ -360,7 +359,7 @@ export default { const iframeWindow = this.$refs.iframe.contentWindow if (iframeWindow && this.data) { try { - // 直接注入 microApp 对象 + // 同源情况,直接注入 microApp 对象 iframeWindow.microApp = { getData: () => this.data } @@ -379,18 +378,6 @@ export default { // console.error('Failed to inject microApp object:', error) } }, - - // 清理注入的 microApp 对象 - cleanupMicroApp() { - try { - const iframeWindow = this.$refs.iframe.contentWindow - if (iframeWindow && iframeWindow.microApp) { - delete iframeWindow.microApp - } - } catch (error) { - // console.error('Failed to clean up microApp object:', error) - } - }, } }