天天看点

开启chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解决方案

前端在开发中经常会遇到跨域的问题,如果出现跨域,控制台会出现如下提示:

开启chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解决方案

关于跨域的原理,这里就不详谈了,我们主要介绍chrome浏览器怎么设置允许跨域。这里的方法使用于49版本以上,相信你的版本不会低于49啦,如果真是这么低,就赶紧升级吧。

一、windows系统

1. 在你的在电脑上新建一个目录,例如:C:\MyChromeDevUserData;

2. 在桌面找到你的chrome浏览器图标,右键--属性,在属性页面中的目标输入框里加上   --disable-web-security --user-data-dir=C:\MyChromeDevUserData,--user-data-dir的值就是刚才新建的目录。

3. 然后点击确定,关闭属性界面。

启动浏览器,如果浏览器出现了如下图所示的提示,则配置成功了。

开启chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解决方案

二、mac系统

首先在你的电脑新建一个空的文件夹,名字任取,如mychromeData,然后打开命令窗口,输入:

open -n /Applications/Google\ Chrome.app/ --args --disable-web-security  --user-data-dir=/Users/hexiufeng/mychromeData

其中Users/hexiufeng/mychromeData就是你新建的文件夹的位置。回车,然后打开chrome浏览器,就可以看到跨域提示了。这是我们可以看到mychromeData文件夹下已经生成了一对文件:

开启chrome跨域模式--No 'Access-Control-Allow-Origin' header is present on the requested resource解决方案

继续阅读