element upload http-request 设置上传进度

dom

class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :http-request="uploadSectionFile"
              :show-file-list="false"
              :before-upload="beforeAvatarUpload">
              if="scope.row.imgUrl" :src="scope.row.imgUrl" class="avatar">
              else class="el-icon-plus avatar-uploader-icon">
   

js

uploadSectionFile(param){
        var fileObj = param.file;
        var form = new FormData();
        form.append("file", fileObj);
        let requestId = uuid.v1().replace(/-/g, '')
        //
        this.$http.post(`/commons_rest/file/upload?catalog=headimg&requestId=${requestId}`,
                        form,
                        {progress:function(event){
                          param.file.percent = event.loaded/event.total*100
                          param.onProgress(param.file)
                        }
        }).then((res)=>{
          console.log(res)
          param.data.list.push({
            name:res.data.name,
            status:"success",
            uid:new Date().getTime(),
            url:res.data.url
          })
        },response => {
          console.log('--->>>>>',response)
        })

      },

你可能感兴趣的:(vue,upload,element)