本地html文件引入本地js文件时报跨域错误

image-20220309105825622

//获得脚本文件被cors政策锁定,跨域请求仅支持协议方案:http,数据,chrome, chrome扩展,chrome-untrusted, https。

image-20220309110510208

解决:

使用vsCode的插件Live Server,可以解决ajax不支持file协议的问题,可以实现在编辑器里保存修改后,页面自动刷新的功能。
安装完成之后,打开html文件后,点击右下角的GoLive 即可。