mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-12 22:40:21 +08:00
fix(stage): render destroy后移除load事件
This commit is contained in:
parent
504adcb017
commit
f03281ac6c
@ -52,15 +52,7 @@ export default class StageRender extends EventEmitter {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
this.iframe.onload = async () => {
|
this.iframe.addEventListener('load', this.loadHandler);
|
||||||
this.emit('onload');
|
|
||||||
if (this.render) {
|
|
||||||
const el = await this.render(this.core);
|
|
||||||
if (el) {
|
|
||||||
this.iframe?.contentDocument?.body?.appendChild(el);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMagicApi = () => ({
|
public getMagicApi = () => ({
|
||||||
@ -113,9 +105,20 @@ export default class StageRender extends EventEmitter {
|
|||||||
* 销毁实例
|
* 销毁实例
|
||||||
*/
|
*/
|
||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
|
this.iframe?.removeEventListener('load', this.loadHandler);
|
||||||
this.contentWindow = null;
|
this.contentWindow = null;
|
||||||
this.iframe?.remove();
|
this.iframe?.remove();
|
||||||
this.iframe = undefined;
|
this.iframe = undefined;
|
||||||
this.removeAllListeners();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user