In my SPA i am dealing with a slightly unusual problem. I am fetching data for each page from static json files. Within these files all the content is represented, including the meta data. Unfortunately i am experiencing that the variable can be null due to its async behaviour and cause an error. How do i work around this?
Here is an example of what i am doing:
export default {
data () {
return {
content: ''
}
},
async asyncData ({req, params}) {
let { data } = await axios.get(`/data/blog/${params.slug}.json`)
return { content: data }
},
head () {
if (this.content.seoMetaTags) {
this.content.seoMetaTags.map((meta) => {
if (meta.tagName === 'title') {
return {
title: 'lol'
}
}
})
}
}
}
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1700">#c1700</a>)</em></sub></div>