Replies: 1 comment
-
I believe the issue is in the script load order. In the first example, the JS runs after the HTML. And in the second example it will work if you change the code to: <div x-data="{...dat(), bar: 'world'}">
<h1 x-text="foo"></h1>
<h2 x-text="bar" @click="baz()"></h2>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.js" defer></script>
<script>
document.addEventListener('alpine:init', () => {
console.log(Alpine);
Alpine.data('dat', () => ({
foo: 'hello',
baz() {
console.log('aboogabooga');
}
}))
})
</script> |
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm fiddling around with Alpine (v3.2.1), and I'm having trouble getting mixins to work. The only message I get in the console is "Script error." which is not very useful...
https://jsfiddle.net/cz683v0w/
Edit: it seems this is the culprit, a breaking change in v3 that made the whole shebang overcomplicated and entirely reliant on magic strings. Just what I love, zero static analysis, hoo boy.
Edit 2: Gritted my teeth and updated the code to
and the result is...

Edit 3: I decided to use it locally instead, thinking perhaps it's the fault of JSFiddle, but it's not rainbows and butterflies in here either.
prints the
Alpine
object to the console, but is promptly followed byand
when clicking an element
Beta Was this translation helpful? Give feedback.
All reactions