浏览器基于安全考虑不允许非同源(协议、域名、端口) url 互通有无。但是在开发阶段,是需要联调后端接口的。
比如从微前端 url 发起请求到后端本地服务,这会形成跨域。没有办法通过配置 CORS 的情况下,可以设置本地浏览器不使用同源策略。
就拿 Chrome 举例,快捷键右键选择属性,将
目标(T) 选项的值替换成
"C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 4" --args --disable-web-security --user-data-dir="C:/ChromeDevSession"
重启 Chrome 就好了。