问题如下:我有13个API,必须在页面启动时执行,但服务器没有等待它们的响应,并显示错误500,直到我执行了几次刷新,我得到状态200,但我不希望这样,我不希望客户端多次刷新,直到它看到响应。
我不明白的是,POSTMAN是如何等待响应的,而Web却不这样做的,每次我更改API的参数时,我都会遇到这种情况
When I change the parameters, some are executed but others are not, I realize that react does not expect the promise and displays it even though it does not bring anything
postman if wait for response
我已经使用了节点代码遗留、axios、请求、超时等,但我无法让它等待请求****我已经在Angular 和React中完成了项目,但我无法。
这是我尝试过的最后一个,我认为有13个API
import React, { useEffect }from 'react';
// import DashboardService from "../services/DashboardService";
import axios from "axios";
import ApiConstants from "../constants/ApiConstants";
const DashBoardRequest = axios.create({
baseURL: ApiConstants.BACKEND_DASHBOARD_API.BASE_API_URL,
timeout: 30000,
});
const HomePage = () =>{
const filteredHeatmap = () => {
return new Promise(async () => {
const params = {
id_enterprise: "9",
date_start: "2022-05-12",
date_end: "2022-07-09",
age_ini: "20",
age_end: "60",
gender_id: "4"
};
await DashBoardRequest.get(
ApiConstants.BACKEND_DASHBOARD_API.GET_FILTERED_HEATMAP,
{params}
).then(
res =>{
console.log(res)
}
)
})
}
async function resFilteredHeatmap(){
await filteredHeatmap()
}
Promise.race([
....
resFilteredHeatmap(),
....
]).then(res=>{
console.log(res)
})
return (
<div>
hola
</div>
)
}
export default HomePage;
1条答案
按热度按时间mnemlml81#