Explicit Mount Target #1888
jonnitto
started this conversation in
3. Feature Ideas
Replies: 2 comments
-
Alpine only searches for Is it about watching the entire DOM for changes (which looks for freshly inserted components)? In V2 you could pause that global observer but maybe not in V3. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Actually, you can use that snippet: function loadAlpineComponent (selector, component) {
const el = document.querySelector(selector);
const uid = "data" + Math.round(Math.random() * Date.now());
component = component || (() => ({}))
if (!el) throw new Error("Invalid element selector: " + selector)
el.setAttribute("x-data", uid);
Alpine.data(uid, component);
Alpine.initTree(el); // requires Alpine 3.2+
};
// usage
const data = () => ({
foo: 'bar',
});
loadAlpineComponent("#test", data) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be great if it would be possible to specify a mount target (selector or element) to limit AlpineJS to only that region of the page:
This also means you can have multiple apps to control different regions on the same page:
This idea is borrowed from Petie-Vue, but I think it would be really usefull, especially if you have user-generated content on the page.
Beta Was this translation helpful? Give feedback.
All reactions