小编Cas*_*Cas的帖子

Nuxt:Head 函数不适用于标题或元标记

我有一个用 Nuxt 构建的网页,对于不同的页面,我希望在头部有不同的标题和不同的元描述。我该怎么做呢?

我在 Nuxt 文档中找到了 head() 方法,但这似乎对我不起作用。

在我的 contact.vue 中:

export default class Contact extends Vue {
   head() {
      return {
         title: 'Contact page',
         meta: [
            { hid: 'description', name: 'description', content: 'This is a contact page' }
         ]
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

在我的 nuxt.config.js 中:

head: {
    title: 'My website',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }
    ],
}
Run Code Online (Sandbox Code Playgroud)

根据文档,我希望这能生成元标记。但它只显示 nuxt.config.js 中声明的标题和元描述。我在这里缺少什么?

html vue.js nuxt.js

5
推荐指数
1
解决办法
4082
查看次数

标签 统计

html ×1

nuxt.js ×1

vue.js ×1