直接上代碼
import axios from 'axios'
const $http = axios.create({
timeout: 100 * 1000,
});
/**
* 入口
*/
async function startTest() {
console.log(1)
let result1 = await test1()
console.log(2)
let result2 = await test2()
console.log(3)
}
/**
* 測試1
*
* 本地休眠3秒
*/
async function test1() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true)
}, 3000)
})
}
/**
* 測試2
*
* 調用一個休眠十秒的遠程接口
*
*/
async function test2() {
return $http.post("http://127.0.0.1:8080/sleep10000", {})
.then((res: any) => {
return "false";
})
}