update component

This commit is contained in:
Harvey Zack committed 2023-04-18 23:04:52 +08:00
1 parent d1156a40b1
commit 70f551b878
3 files changed
+13 -13

No files matched your search

+6 -6
View File
@@ -44,7 +44,7 @@ export default class Component {
this.show = !this.show;
}
async add(getOption) {
add(getOption) {
const option = typeof getOption === 'function' ? getOption(this.art) : getOption;
option.html = option.html || '';
validator(option, ComponentOption);
@@ -96,7 +96,7 @@ export default class Component {
this.cache.set(name, { $ref, events, option });
if (option.mounted) {
await option.mounted.call(this.art, $ref);
option.mounted.call(this.art, $ref);
}
return $ref;
@@ -154,12 +154,12 @@ export default class Component {
events.push(destroyEvent);
}
async remove(name) {
remove(name) {
const item = this.cache.get(name);
errorHandle(item, `Can't find [${name}] from the [${this.name}]`);
if (item.option.beforeUnmount) {
await item.option.beforeUnmount.call(this.art, item.$ref);
item.option.beforeUnmount.call(this.art, item.$ref);
}
for (let index = 0; index < item.events.length; index++) {
@@ -172,9 +172,9 @@ export default class Component {
delete this[name];
}
async update(option) {
update(option) {
const item = this.cache.get(option.name);
if (item) await this.remove(option.name);
if (item) this.remove(option.name);
return this.add(option);
}
}