文章目录

前言

VSCode最近一路高歌猛进,成为最流行的前端开发编辑器之一。不得不说用起来真香,所以平时写项目代码就喜欢搭配IDEA一起使用,主要是因为里面有个Live Server插件,可以实时刷新我所修改的前端页面,但是今天遇到了这个错误:

Refused to apply style from ‘http://127.0.0.1:5500/assets/css/book.css’ because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Refused to apply style from * because its MIME type ('text/html') is not a supported stylesheet 原因

原因

首先这个原因肯定是资源路径引入的不对,经过排查原因是VSCode的问题。因为我建的是Java Web项目, 整个前端文件都放到**Web**目录下,所以IDEA认为 Web 目录就是我项目的根目录,所以在IDEA中,从根目录下,这样引入资源文件其实没问题:
Refused to apply style from * because its MIME type ('text/html') is not a supported stylesheet 原因

但是 VSCode编辑器却认为我的项目的根目录在整个项目的根目录下
Refused to apply style from * because its MIME type ('text/html') is not a supported stylesheet 原因
用相对路径就可以解决这个问题:
Refused to apply style from * because its MIME type ('text/html') is not a supported stylesheet 原因

总结

之所以想从根目录下引入CSS样式文件,是因为项目中的其他文件也需要用到此样式文件,就偷懒想做个html模板,以后的html页面就直接复制粘贴,害。。。。。。

相关文章: