// 假设 fetchData1 和 fetchData2 是返回 Promise 的异步函数
fetchData1()
.then(result1 => {
// 处理 result1
return fetchData2(result1); // 注意这里返回了 fetchData2 的结果
})
.then(result2 => {
// 处理 result2
})
.catch(error => {
// 捕获并处理错误
console.error('Error:', error);
});
之前都以为是这样用的🤦♂️
// 假设 fetchData1 和 fetchData2 是返回 Promise 的异步函数
fetchData1()
.then(result1 => {
// 处理 result1
fetchData2(result1).then(result2 => {
// 处理 result2
console.log(result2)
})
.catch(error => {
// 捕获并处理错误
console.error('Error:', error);
});
})
.catch(error => {
// 捕获并处理错误
console.error('Error:', error);
});