useEffect(async () => { const getFirstResponse = async () => { try { return await axios.get('http://first-api', { params: { carId: id }, }); } catch (error) { return error; } }; const firstResponse = await getFirstResponse(); const getSecondResponse = async () => { try { return await axios.get('http://second-api', { params: { carName: firstResponse.data?.carName }, }); } catch (error) { return error; } }; const secondResponse = await getSecondResponse(); Promise.all([firstResponse, secondResponse]) .then(function (values) { console.log(`values`, values); }) .catch(function (err) { console.log(err); }); }, []);
标签:values,return,hooks,await,react,promise,firstResponse,error,const From: https://www.cnblogs.com/anna001/p/17660182.html