模拟实现axios发送请求
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模拟实现axios发送请求</title>
</head>
<body>
<script>
function Axios(config) {
this.config = config;
}
// 发送请求
Axios.prototype.request = function (config) {
// 创建一个promise实例对象
let promise = Promise.resolve(config);
// 声明一个数组
let chains = [dispatchRequest, undefined]; //undefined 占位
// 调用then方法指定回调
let result = promise.then(chains[0], chains[1]);
// 返回promise的结果
return result;
}
function dispatchRequest(config) {
//