36

使用文件nuxt.config.js文件,head可以自定义内容以添加一些元数据或其他内容:

module.exports = {
  /*
  ** Headers of the page
  */
  head: {
    title: 'awesome title',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'Nuxt.js project' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  ...
}

但是我在文档中找不到任何东西来设置html元素的属性——我想设置lang属性。有没有办法做到这一点?

4

1 回答 1

77

来源:在 HTML 标签中声明语言 · 问题 #388 · nuxt/nuxt.js

head支持一个htmlAttrs属性。它将对象的每个键:值映射为属性:值

module.exports = {
  head: {
    htmlAttrs: {
      lang: 'en'
    },
    title: 'awesome title',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: 'Nuxt.js project' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  ...
}
于 2018-01-13T11:22:23.000 回答