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

[js] 第300天 axios为什么能在浏览器中环境运行又能在node中环境运行? #1882

Open
haizhilin2013 opened this issue Feb 9, 2020 · 2 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第300天 axios为什么能在浏览器中环境运行又能在node中环境运行?

我也要出题

@haizhilin2013 haizhilin2013 added the js JavaScript label Feb 9, 2020
@sayid760
Copy link

源码中defaults.js文件里有getDefaultAdapter这个方法,用来判断环境。如果是浏览器就实例new XMLHttpRequest()来发送请求响应服务,node环境就引用http和https库处理和响应http服务。

@hyj443
Copy link

hyj443 commented Oct 21, 2021

axios的getDefaultAdapter函数可以判断当前环境,浏览器环境会require一个js文件,node环境会require另一个js文件,前者是用promise管控的xhr一套流程,后者是用node的http库发起http请求。

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

No branches or pull requests

3 participants