Replies: 6 comments 2 replies
-
You should be able to use a $store to pass the JSON from the outside to any components using the store. https://alpinejs.dev/globals/alpine-store For example:
Then you can reference it in your component via the |
Beta Was this translation helpful? Give feedback.
-
@MichaelMackus Thanks for the reply. I have actually been trying out You can see in the console log that the data is being fetched but it's not getting "stored" by Alpine. |
Beta Was this translation helpful? Give feedback.
-
@zkwbbr that actually appears to be working for me. For some reason jsfiddle isn't hot-reloading the alpine.js content correctly, but when I do a Ctrl+Shift+r reload in chrome I see the name in the document: |
Beta Was this translation helpful? Give feedback.
-
@MichaelMackus well that is weird. I tested it Chrome/Firefox, it some times appear after several refresh. Looks like a bug? |
Beta Was this translation helpful? Give feedback.
-
I think it is just a side effect from jsfiddle. I noticed the same thing with a few other hot-reloading scripts. It should work just fine in production/html use though I'd guess. |
Beta Was this translation helpful? Give feedback.
-
I tested it in actual Chrome and Firefox (not inside jfiddle) and it does not work. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Usually I can get JSON data using
x-init="myData = await (await fetch('/path/to/json')).json();"
but what if the JSON data is already fetched previously using vanilla JS? e.g.,Beta Was this translation helpful? Give feedback.
All reactions