带 axios 的进度条 [英] Progress Bar with axios

查看:103
本文介绍了带 axios 的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用进度条显示文件的上传状态.我正在使用 axios 发出 http 请求.我从他们的 github 页面https://github.com/mzabriskie/axios/blob/master/examples/upload/index.html

I have to display the upload status of the file using a Progress Bar. I am using axios to make http requests. I followed the example from their github page https://github.com/mzabriskie/axios/blob/master/examples/upload/index.html

我的代码如下:

this.store().then(() => {
    var form = new FormData();
        form.append('video', this.file);
        form.append('uid', this.uid);

        axios.post('/upload', form, {
            progress: (progressEvent) => {
                    if (progressEvent.lengthComputable) {
                       console.log(progressEvent.loaded + ' ' + progressEvent.total);
                       this.updateProgressBarValue(progressEvent);
                    }
           }
       })                   
});

然而,它根本没有执行console.log(progressEvent.loaded + ' ' + progressEvent.total);,也没有调用this.updateProgressBarValue(progressEvent);

However, it is not executing the console.log(progressEvent.loaded + ' ' + progressEvent.total); at all nor is it calling this.updateProgressBarValue(progressEvent);

我该如何解决这个问题??

How can I solve this??

推荐答案

我找到了答案.事件的名称是 onUploadProgress,我使用的是 progress

I found the answer. The name of the event is onUploadProgress and I was using progress

这篇关于带 axios 的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆