I need to load async data and then loop it out in a vue component. I understand that the loop run before I have the data but I cant figure out how to rerun or hold the loop until I have the data. One solution I have tested and that dose not work is a loaded property in Data and a isLoaded computed function and after that -
<div v-if="isLoaded">
<ul v-for="item in menu.items">
<li>{{ item.heading }}</li>
</ul>
</div>
It seems that the loop runs anyway and I got error -
TypeError: Cannot read property 'items' of undefined
The whole page seems to freeze after that error so probably cant I set the Data property loaded to true in the async function. I have tested to run the async in both created and mounted hooks.
When I leave the page and come back everything works, probably because the data has been loaded. I have also tested to set the loded property by button click and it works fine when the loop are out comment and not when the loop run.
I thought this was the common solution after googling but I cant get it to work. Whats wrong or any other suggestions (my last one is to load the data in an other page).
See also -
export default {
data() {
return {
loaded: false,
and -
computed: {
isLoaded() {
return this.loaded
}