【VSCode】from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported

Access to script at ‘file:///C:/Users/dawulei/Desktop/%E9%A1%B9%E7%9B%AE/%E5%9D%A6%E5%85%8B%E5%A4%A7%E6%88%98/txt/htrml/js/txt.js’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
加载js文件时使用了file协议,该协议会导致跨域,而使用htpp、https等协议时则没有跨域问题。

解决方案:
vsCode安装插件Live Server

Live Server
底部注意切换
切换前:

 

切换后:

切换后默认打开:
http://127.0.0.1:5500/htrml/txt.HTML
————————————————
版权声明:本文为CSDN博主「戈叁铭」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_38241002/article/details/113811108

猜你喜欢

转载自blog.csdn.net/lvmengzou/article/details/119691737