feat: add mountComponent utils
This commit is contained in:
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user