文件上传实时获取上传进度(axios)

文件上传实时获取上传进度(axios)

 frontBeforeUploadVideo: function (file) {
        return false;
      },
      // 上传 change
      frontHandleChangeVideo(info) {
        const formData = new FormData()
        formData.append('file', info.file)
        formData.append('token', "token")
        this.saveFile(formData)
      },
      saveFile(formData) {
        this.confirmLoading = true
        this.axios({
          method: 'post',
          url: '/common/upload_file',
          headers: {},
          onUploadProgress(e){
            if(e.lengthComputable){
              console.log('上传进度',e.loaded / e.total); //已上传的比例
            }
          },
          params: {},
          data: formData
        }).then((response) => {
          let that = this;
          this.details.url = response.result.url;
          this.fileSize = response.result.size;
          // 添加定时器解决 that.$refs.video.duration无法获取 NaN
          setTimeout(() => {
            that.$nextTick(() => {
              if (that.details.url) {
                that.timeLength = that.$refs.video.duration;
                this.form.setFieldsValue({
                  duration: that.timeLength,
                });
                that.$refs.video.src = response.result.url;
                this.$message.success("上传成功");
              }
            })
          }, 800)


          this.confirmLoading = false
        }).catch((error) => {
          this.$message.error("上传失败,请重试");
          this.confirmLoading = false
        })

      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值