Reputation: 51
when I use \nuxt\strapi\ nuxt/apollo,it always told Cannot read property 'content' of undefined. if I refresh the page it works!
why?
how can I do for it?
here is my codes
<template>
<div>
<div class="about-content">
<div id="zwqkl" v-html="$md.render(aboutuses[0].content)"></div>
</div>
</div>
</template>
<script>
import aboutusQuery from '~/apollo/queries/aboutus/aboutus'
export default {
name: 'about-us',
data() {
return {
aboutuses: []
}
},
apollo: {
aboutuses: {
query: aboutusQuery
}
}
}
</script>
Upvotes: 0
Views: 365
Reputation: 4904
This answers your question: Nuxt JS Apollo data only available after page refresh
The key is to use the "$loadingKey" property. I updated your code accordingly.
<template>
<div>
<div v-if="!loading" class="about-content">
<div id="zwqkl" v-html="$md.render(aboutuses[0].content)"></div>
</div>
</div>
</template>
<script>
import aboutusQuery from '~/apollo/queries/aboutus/aboutus'
export default {
name: 'about-us',
data() {
return {
loading: 0,
aboutuses: []
}
},
apollo: {
$loadingKey: 'loading',
aboutuses: {
query: aboutusQuery
}
}
}
</script>
Upvotes: 1
Reputation: 111
Can you try to prefetch your result?
apollo: {
prefetch: true,
aboutuses: {
query: aboutusQuery
}
}
Upvotes: 0