本地调试跨域问题解决


问题

本地调试代码过程中遇到访问后台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"
            ],
        },
    ]
}

其他方案:

后台配置跨域等

REFERENCE:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM