问题
本地调试代码过程中遇到访问后台api报跨域问题,又不想去修改后台配置的话,咋办?
解决方案:
- 方案1:修改host
使用switchhosts工具快速切换不同的host配置
//配置host
121.201.93.106 baidu.com cnblogs.com
- 方案2:关闭浏览器安全策略
关闭浏览器安全策略,在vscode启动配置浏览器启动参数,即.vscode->launch.json
设置runtimeArgs
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8180",
"webRoot": "${workspaceFolder}",
"runtimeArgs": [
"--disable-web-security"
],
},
]
}
其他方案:
后台配置跨域等