問題
本地調試代碼過程中遇到訪問后台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"
],
},
]
}
其他方案:
后台配置跨域等