为了衡量进度,我正在考虑在进行 axios 调用时做这两件事:
到目前为止,我只是可以在其中获取数据,但我需要某种方法来获取其背后的元数据(网络控制台中的信息,例如文件大小、到目前为止下载的数量)
const request = axios.get('/data');
request.then((response) => {
}
Run Code Online (Sandbox Code Playgroud)
或者还有其他衡量进展的方法吗?
您只需要使用 onUploadProgress 函数传入一个配置对象:
let progress = 0;
const request = axios.post('/data', {
onUploadProgress: function(event) {
progress = Math.round((event.loaded * 100) / event.total);
}
});
request.then((response) => {
//
}
Run Code Online (Sandbox Code Playgroud)
然后根据需要使用进度变量。
注意:如果使用请求,请按照此处所述get使用onDownloadProgress
| 归档时间: |
|
| 查看次数: |
2621 次 |
| 最近记录: |