update 优化 避免重复包装
This commit is contained in:
@@ -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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user