I have installed Astro with Alpine.js integration.
The following code snippet works fine, but I would like to parameterize the URL.
<div x-data="{
result: null,
async retrieveData() {
this.result = await (await fetch('https://api.sampleapis.com/coffee/hot')).text();
}
}"
x-init="retrieveData()"
>
<span x-text="result"></span>
</div>
…but the following code doesn’t work.
---
const URL='https://api.sampleapis.com/coffee/hot'
---
<div x-data="{
result: null,
async retrieveData() {
this.result = await (await fetch({URL})).text();
}
}"
x-init="retrieveData()"
>
<span x-text="result"></span>
</div>
Any suggestions?