【问题标题】:Response time in Axios ReactjsAxios Reactjs 中的响应时间
【发布时间】:2021-03-09 14:41:56
【问题描述】:

我正在使用以下 sn-p 来访问 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()

请提出解决方法。谢谢

【问题讨论】:

标签: reactjs axios


【解决方案1】:

可以使用原生的Performance接口。

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

【讨论】:

    猜你喜欢
    • 2018-09-06
    • 2022-01-26
    • 2020-09-25
    • 2019-05-01
    • 2020-07-30
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 2022-01-20
    相关资源
    最近更新 更多