首页 > 解决方案 > 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()

请提出解决方法。谢谢

标签: reactjsaxios

解决方案


您可以使用本机性能界面。

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()

推荐阅读