【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

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

底部注意切换

切换前:
【VSCode】from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported
切换后:
【VSCode】from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported
切换后默认打开:
http://127.0.0.1:5500/htrml/txt.HTML

上一篇:MSSQL项目导入数据库:The server version or database compatibility level is not supported


下一篇:python精要(71)-VMDK读写(1)