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

[vue] 你了解axios的原理吗?有看过它的源码吗? #304

Open
haizhilin2013 opened this issue Jun 20, 2019 · 4 comments
Open
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 你了解axios的原理吗?有看过它的源码吗?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 20, 2019
@cj-front
Copy link

cj-front commented Nov 7, 2019

1.axios通过对Promise的封装实现异步请求;
2.
if(answer == '有'){
if(这个问题到此为止){
return ‘有’;
}else{
return '没';
}
}

@ruochuan12
Copy link

@hyj443
Copy link

hyj443 commented Oct 21, 2021

我的逐行分析 深入浅出 Axios 源码(v0.23.0)

@Cai-zhiji
Copy link

axios的工作原理

创建请求:
当通过 Axios 发起一个 HTTP 请求时,它会创建一个请求实例,并配置请求的 URL、方法、请求头、参数、响应类型等。

发送请求:
Axios 使用底层的 XMLHttpRequest 对象(在浏览器中)或 http 模块(在 Node.js 中)来发送请求。它通过调用底层的网络请求 API,将请求发送到服务器。

处理响应:
一旦服务器返回响应,Axios 就会将响应的状态码、响应头和响应数据封装在一个响应对象中。然后,它会检查响应的状态码,并根据状态码的不同来决定是调用 Promise 的 resolve(请求成功)还是 reject(请求失败)。

返回结果:
当响应处理完成后,Axios 将返回一个 Promise 对象。根据 Promise 的状态(成功或失败),可以使用 .then() 或 .catch() 方法来处理响应的数据或错误。

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

No branches or pull requests

5 participants