1
0
mirror of synced 2026-03-23 02:58:34 +08:00

fix(stage): render destroy后移除load事件

This commit is contained in:
roymondchen
2022-03-29 12:44:48 +08:00
committed by jia000
parent 504adcb017
commit f03281ac6c

View File

@@ -52,15 +52,7 @@ export default class StageRender extends EventEmitter {
height: 100%;
`;
this.iframe.onload = async () => {
this.emit('onload');
if (this.render) {
const el = await this.render(this.core);
if (el) {
this.iframe?.contentDocument?.body?.appendChild(el);
}
}
};
this.iframe.addEventListener('load', this.loadHandler);
}
public getMagicApi = () => ({
@@ -113,9 +105,20 @@ export default class StageRender extends EventEmitter {
* 销毁实例
*/
public destroy(): void {
this.iframe?.removeEventListener('load', this.loadHandler);
this.contentWindow = null;
this.iframe?.remove();
this.iframe = undefined;
this.removeAllListeners();
}
private loadHandler = async () => {
this.emit('onload');
if (this.render) {
const el = await this.render(this.core);
if (el) {
this.iframe?.contentDocument?.body?.appendChild(el);
}
}
};
}