[Vuejs]-NuxtJS 2 meta tags SSR from API data

0👍

Use head(){} instead of head: {}

The head property could be Object and Function, you can have dynamic meta/title tags via Function

data() {
   return {
      blog: {}
   }
},
async fetch() {
   let { data } = await axios.get(`/blogs/${this.$route.params.id}`);
   this.blog = data;
},
head() {
    return {
        title: this.blog?.title
    }
}

// or using asyncData
async asyncData({ route }) {
    let { data } = await axios.get(`/blogs/${route.params.id}`);
    return {
        blog: data
    }
},
head() {
    return {
        title: this.blog.title
    }
}

Leave a comment