Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxyTable & axios封装 #3

Open
YUD1112 opened this issue Apr 3, 2019 · 2 comments
Open

proxyTable & axios封装 #3

YUD1112 opened this issue Apr 3, 2019 · 2 comments

Comments

@YUD1112
Copy link

YUD1112 commented Apr 3, 2019

想在config里设置proxyTable来完成跨域,但是发现封装后的axios就不能实现跨域。。。但是直接用axios就可以走config里的proxy配置。。。不知何解?

@ruichengping
Copy link
Owner

ruichengping commented May 16, 2019

首先axios在浏览器是环境,是在XMLHttpRequests上做了一层封装,本质其实就是ajax,既然是ajax就避免不了跨域的问题。对于这种情况,要么服务端的接口加一个响应头Access-Control-Allow-Origin,要么通过node这种中间层帮忙做一个转发。这里的话,你可以用webpack-dev-server去做,具体用法参考这里webpack-dev-server代理配置 至于你说的axios里的proxy,仅仅帮你加个自定头“Proxy-Authorization”而已,并没有解决跨域问题

@YUD1112
Copy link
Author

YUD1112 commented May 17, 2019

嗯嗯,问题已经解决了。。。thx for reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants