feat: add mountComponent utils

This commit is contained in:
chenjiahan
2020-08-31 17:49:19 +08:00
parent 77613e3ee5
commit f02afd882c
5 changed files with 34 additions and 32 deletions
+17
View File
@@ -1,3 +1,5 @@
import { createApp, Component } from 'vue';
export { addUnit, getSizeStyle } from './format/unit';
export { createNamespace } from './create';
@@ -40,3 +42,18 @@ export function pick(obj: Record<string, any>, keys: string[]) {
return ret;
}, {} as Record<string, any>);
}
export function mountComponent(RootComponent: Component) {
const app = createApp(RootComponent);
const root = document.createElement('div');
document.body.appendChild(root);
return {
instance: app.mount(root),
unmount() {
app.unmount(root);
document.body.removeChild(root);
},
};
}