I'm using Nuxt JS/Vue to create an SEO friendly Server Side Rendered JS web app. Nuxt allows setting the head option in each Vue component which it then take and via vue-meta updates the page title. I get a user based on the route and then set the title to the user's name. This works when running a local server. But when I push this up to Firebase I get the title as undefined (on refresh).
Vue Component:
<template>
<div class="user">
<h3>{{ name }}</h3>
</div>
</template>
<script>
import axios from 'axios'
export default {
data () {
return {
title: 'test'
}
},
head () {
return {
title: this.name,
meta: [
{
hid: 'description',
name: 'description',
content: 'My custom description'
}
]
}
},
async asyncData ({ params, error }) {
try {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
return data
} catch (e) {
error({ message: 'User not found', statusCode: 404 })
}
},
mounted () {
console.log(this.name)
this.title = this.name
}
}
</script>
I am having the same issue and I solved using this. Add the below code in your page in script tag under export default {}.