如何使用Nuxt在html元素上设置lang属性?

JavaScript Vue.js

Tom凯

2020-03-23

使用文件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属性。有没有办法做到这一点?

第2962篇《如何使用Nuxt在html元素上设置lang属性?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
吃花椒的猫酱 2021.03.22

根目录下加个app.html

<!DOCTYPE html>

<html lang="zh-Hans">

  <head>

    {{HEAD}}

  </head>

  <body>

    {{APP}}

  </body>

</html>

试试这个能不能解决你的问题,改配置文件会多一个data-n-head属性,不建议

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android