如何解决如何获取本地响应的响应时间?
我想了解请求和响应之间的时差。例如,在下面的代码中,完成请求的时间间隔是多少?
fetch(baseUrl+"recs/rech/non consulté")
.then((response) => response.json())
.then((json) => setReclamations(json))
.then(console.log(setReclamations))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
解决方法
本机与否,答案保持不变。
const start = new Date();
fetch(baseUrl+"recs/rech/non consulté")
.then((response) => {console.log(new Date() - start); return response.json()})
.then((json) => {console.log(new Date() - start); return setReclamations(json)})
.then(console.log(setReclamations))
.catch((error) => console.error(error))
.finally(() => setLoading(false));
每个新的console.log都将显示从那时到运行提取之间的时间之间的差异。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。