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
底部注意切换
切换前:
切换后:
切换后默认打开:
http://127.0.0.1:5500/htrml/txt.HTML