reactjs - Axios Reactjs 中的响应时间
问题描述
我正在使用以下代码段来访问 API 并获得其响应。我想知道获取数据需要多少时间
const fetch_table_data = async () => { const response = await axios.get(`URL_HERE`, {headers : {'Authorization': 'Token abc'}});if (response.status === 200){
// what is the time taken to fetch this data??? <-------------------
}}
fetch_table_data()
请提出解决方法。谢谢
解决方案
您可以使用本机性能界面。
const fetch_table_data = async () => {
const request_start_at = performance.now();
const response = await axios.get(`URL_HERE`, {
headers : {
'Authorization': 'Token abc'
}
});
const request_end_at = performance.now();
const request_duration = request_ent_at - request_start_at;
if (response.status === 200) {
console.log(duration);
}
}
fetch_table_data()
推荐阅读
- dart - 如何在抽屉中对齐扩展图块中的子标题?
- android - 创建未签名的 APK 导致 NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/codec/binary/Base64;
- kubernetes - Kubectl 命令列出 Kubernetes 中部署的 pod
- spring - 处理“curl ...-data”的Rest Endpoint
- node.js - 如何正确处理 Axios 中的参数和查询?
- php - 在 PHP 中验证以太坊(Web3)签名的消息
- java - Spring data JPA 使用 Beanutils.copyProperties 更新一对多关系
- python - 我可以使用 Firebase 函数来接收应该发送到端口上的服务器的数据吗?
- python - 在python中将首字母与全名输入分开而不使用split
- assembly - 如何从 qword(四字)中减去 dword(双字)?