Add mount

This commit is contained in:
2026-04-08 11:51:40 +02:00
parent b75d1175a5
commit fc148fdbcc

17
sw.js
View File

@@ -295,6 +295,23 @@ export const Router = (routes) => {
});
};
export const mount = (root, target, props = {}) => {
const dest = typeof target === 'string' ? document.querySelector(target) : target;
if (!dest) return;
while (dest.firstChild) remove(dest.firstChild);
const el = h(root, props);
dest.appendChild(el);
if (el.$c) {
el.$c.m.forEach(f => f());
el.$c.m.length = 0;
}
return () => remove(el);
};
export default (target, root, props) => {
const el = h(root, props);
target.appendChild(el);