admin管理员组文章数量:1300020
I'm working on a nuxtJS project and not much know about nuxt or vue, what I want is change page title, but it show one title for all page, that title belong to one ponent, I removed that title and now it show nothing. I put this code in header ponent
<script>
export default {
name: "header",
head () {
return {
title: this.title
}
},
data () {
return {
title: 'Hello World!'
}
}
}
</script>
and in nuxtjs config :
module.exports = {
head: {
title: pkg.name
}
...
}
What I want, show title of each page dynamically.
I'm working on a nuxtJS project and not much know about nuxt or vue, what I want is change page title, but it show one title for all page, that title belong to one ponent, I removed that title and now it show nothing. I put this code in header ponent
<script>
export default {
name: "header",
head () {
return {
title: this.title
}
},
data () {
return {
title: 'Hello World!'
}
}
}
</script>
and in nuxtjs config :
module.exports = {
head: {
title: pkg.name
}
...
}
What I want, show title of each page dynamically.
Share asked Sep 7, 2019 at 12:25 Jack The BakerJack The Baker 1,9033 gold badges26 silver badges63 bronze badges3 Answers
Reset to default 7Your nuxt.config.js
override title set in your page.
You should use titleTemplate in nuxt.config.js
:
head: {
titleTemplate(titleChunk) {
return titleChunk ? titleChunk : pkg.name
}
}
By this way, you can also format title for every page with you site name:
head: {
titleTemplate(titleChunk) {
return titleChunk ? `{pkg.name} - ${titleChunk}` : pkg.name
}
}
titleChunk
e from head.title
of your page like you already do.
There are only option to set the title dynamic base on your pages is like override the head function Let me show you one example here
export default {
...
head () {
return {
title: 'YOUR PAGE TITLE',
meta: [
{ hid: 'og-title', property: 'og:title', content: 'YOUR PAGE TITLE },
...
]
}
}
}
To prevent the overwrite parent meta fields, your hid should be unique
For more information, please visit the official document of the NuxtJs: https://nuxtjs/api/pages-head/
I am using nuxt version 2.15.7
. This syntax is working correctly for me:
nuxt.config.js file
head: {
titleTemplate: '%s',
title: 'info-book', // the title you define. you must put your package-name here, if you want that name.
}
And then in the ponent that you want to define title dynamically, you have this code:
head() {
return {
title: "info-book - " + this.titleHead,
}
},
data () {
return {
titleHead: "dynamic-title"
}
},
本文标签: javascriptNuxtJS page title not changeStack Overflow
版权声明:本文标题:javascript - NuxtJS page title not change - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741628734a2389232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论