SoFunction
Updated on 2025-04-04

Solve the problem of successful callback on-success only once in batch upload of el-upload

el-upload batch upload only executes successful callback on-success

Delete:

file-list="fileList"

I found a solution online and found that I could just cancel the file-list binding. There are also custom upload events methods online, but this is more convenient to operate.

The above method is still a bit problematic. The correct method is to create a temporary variable filelist2 when pulling data in the background, then assign the background data filelist to filelist2, and then bind filelist2 (:file-list="filelist2")

Then the operations on the data are all in the filelist.

el-upload custom upload callback upload success and failure events

template part:

<el-upload
  class="el_upload_above"
  action=""
  ref="upload"
  :limit="limitnum"
  list-type="picture-card"
  :http-request="uploadSectionFile"
  :auto-upload="true"
  :file-list="fileList"
  :on-error="uploadFileError"
  :on-success="uploadFileSuccess"
  :on-exceed="exceedFile"
  :on-remove="removeFile">
</el-upload>

script part:

&lt;script&gt;
  export default {
    data() {
      return {
          fileList:[],//Uploaded file list          limitnum:2,//The maximum number of uploads allowed      };
    },
    methods: {
        //Custom upload        uploadSectionFile(param){
             var fileObj = ;
          var form = new FormData();
           // File object          ("file", fileObj);
          this.$('/file/upload',form).then(res =&gt; {
            (res)
          }).catch(({err}) =&gt; {
            (err)
          })  
        },
          //Upload failed        uploadFileError(err, file, fileList){
          this.$("Upload failed!")
        },
          //Upload successfully        uploadFileSuccess(response, file, fileList){
          if(==0){
            =;
            (file)
          }else{
            this.$();// File upload error message          }
        },
        // Hook when the number of files exceeds the limit        exceedFile(files, fileList){
          this.$('Uploadable only'++'A file');
        },
        //Delete the file        removeFile(file,fileList) {
          =fileList;
        },
    }
  }
&lt;/script&gt;

Comments

After a custom upload, success and failure need to be triggered in the custom upload code (onSuccess/onError). In the component part, you need to write a file upload or a failed callback event (uploadFileSuccess/uploadFileError)

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.