Refused to execute script from ‘‘ because its MIME type (‘text/html‘) is not executable, and strict

报错如下:

 

Refused to execute script from 'http://localhost:8080/style.js?v=1.1' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

造成这个报错的情况有很多,比如服务器配置错误、缓存问题、代码错误、应用部署问题等等

这篇文章是在前端项目运行时产生的问题,

原因就是我在vue.config.js中设置了静态资源公共路径:

所以,重点来了,在public下的所有图片、js等等都属于静态资源,所以使用的时候同样要加上图第四行配置/admin/,如我的public目录下有个style.js文件:

那么,在index.html里引用的时候同样需要加上/admin/,如:

 

这样能够正常访问到style.js,尽管看起来不在/admin/目录下,但是因为上边第一张图我们已经配置过了,所以一定要加上./admin/

否则就会报错:

猜你喜欢

转载自blog.csdn.net/qq_68155756/article/details/132424499