javascript - 如何使用 nuxtjs 在 vue 模板上添加标题和脚本
问题描述
我想为 SEO 添加title
和description
其他 html meta
。
我如何在 vue 模板中做到这一点?
例如我想meta
在我的template.vue
.
出于某种原因,我也必须在该模板上添加脚本。
我的代码是这样的:
head: {
title: 'my title',
script: [
{ src: '/js/theme.js', defer: true }
]
},
上面的代码是错误的。
如果我像这样使用返回:
head () {
return {
title: this.title,
meta: [
{ hid: 'description', name: 'description', content: 'My custom description' }
],
script: [
{ src: '/js/theme.js', defer: true }
]
}
}
meta
会工作,但脚本不会显示。
就像我说的,我不能把脚本放在nuxt-config.js
不知道为什么,但是页面会出错。
解决方案
推荐阅读
- flutter - 如何设置嵌入文本的样式?
- python - pandas 在重新格式化单元格时保留样式 - 无需将字符串重新解析为数字
- javascript - 有没有办法从 URL 中获取现有的子目录和文件?
- javascript - python selenium set value of textarea with javascript 不起作用
- javascript - 仅在某些情况下重定向
- python-3.x - 多窗口应用
- asp.net - 从 URL 查询字符串传递十六进制字符串在 ASP MVC 中不起作用
- swift - 关闭模式后如何连续运行另一个进程
- php - Dompdf 在 cellmap 中找不到错误帧
- android - 将 ByteArrayOutputStream 作为文件写入 data/data/packagename/files