mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-16 03:58:12 +00:00
no message
This commit is contained in:
parent
acdf23571c
commit
4f2bf7549c
@ -80,15 +80,14 @@ export default {
|
|||||||
this.boundHandleLoad = this.handleLoad.bind(this);
|
this.boundHandleLoad = this.handleLoad.bind(this);
|
||||||
this.boundHandleError = this.handleError.bind(this);
|
this.boundHandleError = this.handleError.bind(this);
|
||||||
|
|
||||||
this.injectMicroApp();
|
|
||||||
window.addEventListener('message', this.boundHandleMessage);
|
window.addEventListener('message', this.boundHandleMessage);
|
||||||
this.$refs.iframe.addEventListener('load', this.boundHandleLoad);
|
this.$refs.iframe.addEventListener('load', this.boundHandleLoad);
|
||||||
this.$refs.iframe.addEventListener('error', this.boundHandleError);
|
this.$refs.iframe.addEventListener('error', this.boundHandleError);
|
||||||
|
|
||||||
|
this.injectMicroApp();
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.cleanupMicroApp();
|
|
||||||
|
|
||||||
// 正确移除事件监听器
|
// 正确移除事件监听器
|
||||||
if (this.boundHandleMessage) {
|
if (this.boundHandleMessage) {
|
||||||
window.removeEventListener('message', this.boundHandleMessage);
|
window.removeEventListener('message', this.boundHandleMessage);
|
||||||
@ -360,7 +359,7 @@ export default {
|
|||||||
const iframeWindow = this.$refs.iframe.contentWindow
|
const iframeWindow = this.$refs.iframe.contentWindow
|
||||||
if (iframeWindow && this.data) {
|
if (iframeWindow && this.data) {
|
||||||
try {
|
try {
|
||||||
// 直接注入 microApp 对象
|
// 同源情况,直接注入 microApp 对象
|
||||||
iframeWindow.microApp = {
|
iframeWindow.microApp = {
|
||||||
getData: () => this.data
|
getData: () => this.data
|
||||||
}
|
}
|
||||||
@ -379,18 +378,6 @@ export default {
|
|||||||
// console.error('Failed to inject microApp object:', error)
|
// 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)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user