add beforeUnmount

This commit is contained in:
Harvey Zack committed 2023-04-18 22:58:16 +08:00
1 parent 645e2e2ec3
commit 13f3398765
4 files changed
+15 -4

No files matched your search

+5 -1
View File
@@ -97,7 +97,7 @@ export default class Component {
}
this[name] = $ref;
this.cache.set(name, { $ref, events });
this.cache.set(name, { $ref, events, option });
return $ref;
}
@@ -158,6 +158,10 @@ export default class Component {
const item = this.cache.get(name);
errorHandle(item, `Can't find [${name}] from the [${this.name}]`);
if (item.option.beforeUnmount) {
item.option.beforeUnmount.call(this.art, item.$ref);
}
for (let index = 0; index < item.events.length; index++) {
const destroyEvent = item.events[index];
this.art.events.remove(destroyEvent);
+6 -1
View File
@@ -91,10 +91,15 @@ export type ComponentOption = {
click?(this: Artplayer, component: Component, event: Event): void;
/**
* Wnen the component was mounted
* When the component was mounted
*/
mounted?(this: Artplayer, element: HTMLElement): void;
/**
* When the component was before unmount
*/
beforeUnmount?(this: Artplayer, element: HTMLElement): void;
/**
* Component tooltip, use in controls
*/