简体   繁体   English

nuxt.config.js 没有加载.css 个文件

[英]nuxt.config.js not loading .css files

I am attempting to include my meta information (mostly visible in the static.css and.js files) to my Nuxt application by adding them into nuxt.config.js.我试图通过将元信息(主要在 static.css 和 .js 文件中可见)包含到我的 Nuxt 应用程序中,方法是将它们添加到 nuxt.config.js 中。 I am expecting all of my global meta tags (charset, keywords, etc) as well as my CSS to be loaded when I reload the project on the page I'm testing on, however only using the local vue-meta section gives these desired results.我希望在我正在测试的页面上重新加载项目时加载我所有的全局元标记(字符集、关键字等)以及我的 CSS,但是仅使用本地 vue-meta 部分可以提供所需的这些结果。 I would like to be able to have most of my meta in the configuration file, so while leaving everything in each page is an option,it is not the one I would like to take.我希望能够在配置文件中包含我的大部分元数据,因此虽然将所有内容都保留在每个页面中是一种选择,但这不是我想要的。

I get no warnings or errors when loading the page, which makes me believe that it's not a problem, but I have just started using this file and would like to know if it is something trivial加载页面时我没有收到任何警告或错误,这让我相信这不是问题,但我刚刚开始使用这个文件,想知道它是否是微不足道的

The head I am trying to implement in nuxt.config.js is below.下面是我试图在 nuxt.config.js 中实现的头部。 All file paths are valid (since they are what I use in the individual pages and they work just fine.所有文件路径都是有效的(因为它们是我在各个页面中使用的路径,而且它们工作得很好。

module.export = {
head:{
    meta: [
      {charset: 'utf-8'},
      {
        name: 'keywords', content: '~some keywords~'
      },
    ],
    link: [
      { rel: 'stylesheet', href: '/css/style.css' },
      { rel:'stylesheet', href:'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css'},
      { rel:'canonical', href:'https://www.self.com' }

    ],
    script: [
      {src: 'https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js'},
      {src: 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js'},
      {src: 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'},
    ]
  },
//...
}

I also have a similar body in my css: section, however that produced no results as well.我的css:部分也有一个类似的正文,但是也没有产生任何结果。

I believe you are missing a period ( . ) in your CSS link href , try: href: ' .我相信您在 CSS 链接href中缺少句点 ( . ),请尝试:href: ' /css/style.css' /css/style.css'

Also you can try adding CSS as a property of your head object:您也可以尝试将 CSS 添加为头部 object 的属性:

head {
link: [...],
css: ["./css/style.css"],
script: [...]
}/*end of head*/

If you try the second option then remove the CSS ref from your link array.如果您尝试第二个选项,则从您的链接数组中删除 CSS ref。

Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM