I have this view:
<template>
<ion-page>
<ion-router-outlet></ion-router-outlet>
<suspense>
<template #default>
{{ pages }}
</template>
<template #fallback>
<div>Loading...</div>
</template>
</suspense>
</ion-page>
</template>
...
async setup() {
const storageRef = storage.ref();
const bookRef = storageRef.child("content/books/bk0000001");
const pages = await bookRef.listAll();
console.log({ pages }); // is logged correctly
return { pages }
}
Although it seems to load the content fine but the template is not rendered, the page remains empty neither the default
not the fallback
content is displayed.
What am I doing wrong?
When a component's
setup()
isasync
, the component has to be within a<suspense>
in the parent of the component (not in the component itself).You should move the
{{ pages }}
markup and the data fetching from theasync setup()
into its own component:And update the parent to use the new component in a
<suspense>
:demo 1
Alternatively, you could rewrite the above into a non-async
setup()
, using anonMounted
async hook instead:demo 2