async/await
语法就行了:
async function request() {
const res1 = await axios.get('abc');
const res2 = await axios.get('def');
console.log(res1, res2);
}
一楼楼那个写法不能在请求中间打断,有时候下一个请求需要上一个请求的数据时就不能那样写,await
就可以:
async function request() {
const res1 = await axios.get('abc');
const res2 = await axios.post('def', res1.data);
console.log(res1, res2);
}