发布时间:2023-05-05 文章分类:WEB开发, 电脑百科 投稿人:王小丽 字号: 默认 | | 超大 打印

跨源资源请求问题解决方案

问题描述:当我们在vsCode中使用 open in brower插件打开html文件文件时,就会报错 xxx已被CORS策略阻止,引入的资源还会失效。

from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported for ...

解决办法1 :Live Server插件

在vsCode的插件市场中搜索并安装Live Server插件:

安装好后,右键要打开的文件,就会出现“Open with Live Serve”选项,这样打开文件就不会报错了:

from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported for ...

解决办法2:anywhere

在vsCode控制台或者cmd中安装npm install anywhere -g

from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported for ...

在要打开文件的路径下输入anywhere

from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported for ...

按上面的路径访问

浏览器就会显示可打开的文件。