File tree Expand file tree Collapse file tree 1 file changed +3
-16
lines changed
resources/assets/js/components/MicroApps Expand file tree Collapse file tree 1 file changed +3
-16
lines changed Original file line number Diff line number Diff line change @@ -80,15 +80,14 @@ export default {
80
80
this .boundHandleLoad = this .handleLoad .bind (this );
81
81
this .boundHandleError = this .handleError .bind (this );
82
82
83
- this .injectMicroApp ();
84
83
window .addEventListener (' message' , this .boundHandleMessage );
85
84
this .$refs .iframe .addEventListener (' load' , this .boundHandleLoad );
86
85
this .$refs .iframe .addEventListener (' error' , this .boundHandleError );
86
+
87
+ this .injectMicroApp ();
87
88
},
88
89
89
90
beforeDestroy () {
90
- this .cleanupMicroApp ();
91
-
92
91
// 正确移除事件监听器
93
92
if (this .boundHandleMessage ) {
94
93
window .removeEventListener (' message' , this .boundHandleMessage );
@@ -360,7 +359,7 @@ export default {
360
359
const iframeWindow = this .$refs .iframe .contentWindow
361
360
if (iframeWindow && this .data ) {
362
361
try {
363
- // 直接注入 microApp 对象
362
+ // 同源情况, 直接注入 microApp 对象
364
363
iframeWindow .microApp = {
365
364
getData : () => this .data
366
365
}
@@ -379,18 +378,6 @@ export default {
379
378
// console.error('Failed to inject microApp object:', error)
380
379
}
381
380
},
382
-
383
- // 清理注入的 microApp 对象
384
- cleanupMicroApp () {
385
- try {
386
- const iframeWindow = this .$refs .iframe .contentWindow
387
- if (iframeWindow && iframeWindow .microApp ) {
388
- delete iframeWindow .microApp
389
- }
390
- } catch (error) {
391
- // console.error('Failed to clean up microApp object:', error)
392
- }
393
- },
394
381
}
395
382
}
396
383
< / script>
You can’t perform that action at this time.
0 commit comments