Skip to content

How do I access x-data from a function in an external file? #1262

Answered by SimoTod
leo-petrucci asked this question in 1. Help
Discussion options

You must be logged in to vote

You shouldn't mix the approaches. If you use Alpine and you decide to use an external file, the whole component needs to be extracted. this on an external function will never be your Alpine scope (this is how javascript works, though).
In general, the logic is the same as the index file, you just need to export the component on the window object if you use a bundler like webpack.

See https://codepen.io/SimoTod/pen/QWdBOYP

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@leo-petrucci
Comment options

Answer selected by leo-petrucci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants