vue nuxt,在 header 标题 SEO 上传递 API 值
vue nuxt, passing API value on header title SEO
如何将我的 api 值传递给 vue 上的 Header 标题?我正在使用 nuxt。
我尝试使用它,但出现错误 'blog is not defined'
async asyncData({params, error}) {
try {
let topBlogger = await axios.get('http://api.bla.bla/API/topblogger.php')
let isi = await axios.get(`http://api.bla.bla/API/news.php?id_artikel=${+params.id}`)
let tagList = await axios.get('https://api.bla.bla/users')
return {
bloggers: topBlogger.data,
blog: isi.data,
tags: tagList.data,
}
} catch (e) {
error({message: 'User not found', statusCode: 404})
}
},
head () {
return {
title: blog.id_artikel+' | title bla bla',
meta: [
{ hid: 'description', name: 'description', content: 'content dll' }
]
}
},
但是当我在 <template></template>
上使用博客时它起作用了
我是 vueJS 的新手,所以似乎仍然不太了解它是如何工作的
您需要使用此访问数据
return {
title: this.blog.id_artikel+' | title bla bla',
meta: [
{ hid: 'description', name: 'description', content: 'content dll' }
]
}
这可能对您有所帮助。
<script>
export default {
head: {
title: this.blog.id_artikel+' | title bla bla',
meta: [
{
hid: 'description',
name: 'description',
content: 'Home page description'
}
],
}
}
</script>
如何将我的 api 值传递给 vue 上的 Header 标题?我正在使用 nuxt。
我尝试使用它,但出现错误 'blog is not defined'
async asyncData({params, error}) {
try {
let topBlogger = await axios.get('http://api.bla.bla/API/topblogger.php')
let isi = await axios.get(`http://api.bla.bla/API/news.php?id_artikel=${+params.id}`)
let tagList = await axios.get('https://api.bla.bla/users')
return {
bloggers: topBlogger.data,
blog: isi.data,
tags: tagList.data,
}
} catch (e) {
error({message: 'User not found', statusCode: 404})
}
},
head () {
return {
title: blog.id_artikel+' | title bla bla',
meta: [
{ hid: 'description', name: 'description', content: 'content dll' }
]
}
},
但是当我在 <template></template>
上使用博客时它起作用了
我是 vueJS 的新手,所以似乎仍然不太了解它是如何工作的
您需要使用此访问数据
return {
title: this.blog.id_artikel+' | title bla bla',
meta: [
{ hid: 'description', name: 'description', content: 'content dll' }
]
}
这可能对您有所帮助。
<script>
export default {
head: {
title: this.blog.id_artikel+' | title bla bla',
meta: [
{
hid: 'description',
name: 'description',
content: 'Home page description'
}
],
}
}
</script>