使用Nuxt开发Vue-SSR项目,在nuxt.config.js中统一配置了head:

1
2
3
4
5
6
7
8
9
10
11
head: {
title: '这是title',
meta: [
{ charset: 'utf-8' },
{ name: 'renderer', content: 'webkit' },
{ name: 'force-rendering', content: 'webkit' },
{ 'http-equiv': 'X-UA-Compatible', content: 'IE=Edge,chrome=1' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
// code ...
]
},

开发中发现在首页中,以上meta添加不上,切换其他页面后才会添加。
原因: 在index.vue中,设置了head函数,却未返回任何内容,其他页面都返回了正确的内容,故切换页面才正常添加:

1
2
3
4
export default {
head() {
}
}

page文件的head方法,要么不写,写了就至少需要返回一个对象

1
2
3
4
5
6
export default {
head() {
return {
}
}
}