Feat: add custom mount component

This commit is contained in:
Lazy 2023-10-17 16:16:46 +08:00
parent 6abe0c37d0
commit 10020b59ad

View File

@ -0,0 +1,34 @@
import { createApp, type Component } from "vue";
import { sleep } from "@/tools/commom";
export function useMountComponent() {
let isOpen = false;
const mount = <T>(component: Component) => {
if (isOpen) return;
isOpen = true;
return new Promise<T>((resolve, reject) => {
const div = document.createElement("div");
document.body.appendChild(div);
const app = createApp(component, {
async destroyComponent(delay = 0) {
console.log(delay);
await sleep(delay);
app.unmount();
div.remove();
isOpen = false;
},
emitResult(data: T) {
isOpen = false;
resolve(data);
}
});
app.mount(div);
});
};
return {
mount
};
}