Node.js 在多次请求后,Axios无法从服务器获取数据
我有React&NodeJS应用程序,我正在从服务器获取数据,它可以工作,但仅适用于几个请求,在5或6次重新加载页面axios后不再获取数据,我不再使用任何速率限制Node.js 在多次请求后,Axios无法从服务器获取数据,node.js,reactjs,express,axios,Node.js,Reactjs,Express,Axios,我有React&NodeJS应用程序,我正在从服务器获取数据,它可以工作,但仅适用于几个请求,在5或6次重新加载页面axios后不再获取数据,我不再使用任何速率限制 axios.get('/api/customer-base/') .then(res => res.data) .then(data=>{ console.log(`${data.rooms} dasd`) dispatch({ type: FETCH_ROOMS, pay
axios.get('/api/customer-base/')
.then(res => res.data)
.then(data=>{
console.log(`${data.rooms} dasd`)
dispatch({
type: FETCH_ROOMS,
payload: {
rooms: JSON.parse(data.rooms),
loading: false
}
})
})
.catch(err=>{
if(err.response.data.redirect){
window.location.replace(err.response.data.redirect)
}else{
dispatch({
type: CUSTOMER_BASE_ERROR,
payload: {
error: err.response.data.message
}
})
}
})
这是axios代码。这是快车
router.get('/', async (req,res)=>{
try{
let rooms = await Rooms.find({}).populate('reserver');
console.log(rooms);
return res.status(200).send({
rooms: JSON.stringify(rooms)
})
}catch(err){
return res.status(500).send({
message: err.message
})
}
})
那么问题是什么呢?您是否遇到过此类问题?您是否尝试过使用UI端请求的绝对URL?dev tools中的network(网络)选项卡是否显示您要发出的API请求,以及在同一选项卡中看到的任何HTTP错误?这可能是缓存问题,您能否在axios url上添加时间戳并重试?axios.get(
/api/customer base?timestamp=${new Date().getTime()}
)在断开与服务器的连接后,它会在控制台中记录网络错误添加时间戳时该怎么办?您将尝试检查问题是否继续存在。