工作中遇到的跨域问题
vue 本地起服务,端口号是 3030
vue.XXX.com:3030 代理到了 127.0.0.1(localhost)
vue.XXX.com:3030 访问后端地址 mall.XXX.com 报跨域问题 如下图所示


携带 cookie 时,需要设置如下参数,由于安全策略的影响
1
| axios.defaults.withCredentials = true;
|
1 2 3
| Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: 'http://vue.iqiyi.com:3030'
|
去掉浏览器同源策略影响
- mac 环境:
terminal 中输入以下命令,打开浏览器
1 2 3
| open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/XXX/Documents/MyChromeDevUserData
|
- 谷歌浏览器地址栏输入:chrome://flags/
- 找到:SameSite by default cookies、Cookies without SameSite must be secure
- 设置上面这两项设置成 Disable