-
-
Notifications
You must be signed in to change notification settings - Fork 9k
Closed
Description
What problem does this feature solve?
Currently a top-level await in a <script setup> block causes the template not to render, see this StackOverflow question. Although there are various workarounds, using top-level await is the most natural solution to the common "fetch data from the REST API and display it in the component when it loads" problem.
What does the proposed API look like?
Perhaps we can simply compile a top-level $await in a non-Suspense component to a Promise.then(), so that this snippet
<script setup>
let data = ref('')
data.value = $await getDataFromApi()
</script>would be compiled to
<script setup>
let data = ref('')
getDataFromApi().then(d => data.value = d)
</script>Disclaimer: this is just a wild idea, there may be caveats that I'm unable to see at this moment and there may be better ways to achieve this.
dhulme, SamJ26, nickenchev and BadgerCode
Metadata
Metadata
Assignees
Labels
No labels