首页 > 解决方案 > 如何使用 nuxtjs 在 vue 模板上添加标题和脚本

问题描述

我想为 SEO 添加titledescription其他 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不知道为什么,但是页面会出错。

标签: javascriptvue.jsnuxt.js

解决方案


在此处输入图像描述检查这张图片希望它会帮助你的问题


推荐阅读