vuestic-ui
Version:
Vue 3 UI Framework
46 lines (45 loc) • 1.08 kB
JavaScript
import { getCurrentInstance, nextTick, render, h } from "vue";
const destroy = (el, vNode) => {
if (el) {
render(null, el);
el.remove();
}
el = null;
};
const mount = (component, { props, appContext } = {}) => {
const el = document == null ? void 0 : document.createElement("div");
document.body.appendChild(el);
const vNode = h(component, {
...props,
stateful: (props == null ? void 0 : props.stateful) ?? true
});
if (appContext) {
vNode.appContext = appContext;
}
if (el) {
render(vNode, el);
}
return { vNode, el };
};
const useMount = (component) => {
var _a;
const appContext = (_a = getCurrentInstance()) == null ? void 0 : _a.appContext;
if (!appContext) {
throw new Error("useMount can be used only in setup function");
}
const createInstance = (props) => {
const { vNode, el } = mount(component, { props, appContext });
return () => {
nextTick(() => {
destroy(el);
});
};
};
return {
createInstance
};
};
export {
useMount as u
};
//# sourceMappingURL=useMount.js.map