update 优化 避免重复包装

This commit is contained in:
疯狂的狮子Li
2026-03-25 10:32:45 +08:00
parent 1442d539e8
commit 13a41679bc
+7 -4
View File
@@ -12,6 +12,7 @@ interface Options {
export function createCustomNameComponent(loader: () => Promise<any>, options: Options = {}): () => Promise<Component> { export function createCustomNameComponent(loader: () => Promise<any>, options: Options = {}): () => Promise<Component> {
const { name } = options; const { name } = options;
let component: Component | null = null; let component: Component | null = null;
let wrappedComponent: Component | null = null;
const load = async () => { const load = async () => {
try { try {
@@ -27,13 +28,15 @@ export function createCustomNameComponent(loader: () => Promise<any>, options: O
await load(); await load();
} }
return Promise.resolve( if (!wrappedComponent) {
defineComponent({ wrappedComponent = defineComponent({
name, name,
render() { render() {
return h(component as Component); return h(component as Component);
} }
}) });
); }
return Promise.resolve(wrappedComponent);
}; };
} }