Use the upload component in iview to upload multiple files and trigger the callback function only once

use upload component, set mutiple mode, set on-success and on-progress and monitor its callback
1, click the upload file button
2, select multiple files and upload
3, detect file upload and callback when successful

The

file can be uploaded to the server normally, and the server upload API returns 200 ok, correctly, but the front-end component only receives one on-success callback and handles it correctly. Although other tasks are successful, you can see in the fileList of the callback, percentage=100, but showProgress is always true,file.response and does not exist. A callback should be triggered after each file is uploaded successfully

the official issue of iview is as follows: https://github.com/iview/ivie.

                <Upload
                    ref="upload"
                    :show-upload-list="false"
                    :on-success="handleSuccess"
                    :default-file-list="productImgList"
                    :format="["jpg","jpeg"]"
                    :max-size="1024"
                    :on-format-error="handleFormatError"
                    :on-exceeded-size="handleMaxSize"
                    :before-upload="handleBeforeUpload"
                    multiple
                    type="drag"
                    :action="uploadUrl"
                    class="upload-comp"
                    v-show="productImgList.length < 6">
                <div class="upload-icon">
                </div>
            </Upload>
            
          handleSuccess (res, file, fileList) {
            let self = this;
            this.fileList = []
            if (Array.isArray(fileList)) {
                fileList.forEach((item) => {
                    this.fileList.push(item)
                })
            }
            this.fileList = fileList
            self.$nextTick(function(){
                self.$validator.validate("upload"+ self.index);
            });
        },

then:

  watch: {
        fileList(newArr, oldArr) {
            console.log(JSON.stringify(oldArr))
            if (Array.isArray(newArr)) {
                for (let i = 0, len = newArr.length; i < len; iPP) {
                    if (newArr[i].status === "finished"){
                        // console.log(newArr[i])
                        if (newArr[i].response && newArr[i].response.code === "success") {
                            this.productImgList.splice(i, 1, Object.assign({}, newArr[i], {
                                name: newArr[i].response.data,
                                url: global.IMG_URL + newArr[i].response.data,
                                fileName: newArr[i].response.data
                            }))
                        }
                    }
                }
            }
            // console.log(JSON.stringify( this.productImgList))
        }
    }

but only one successful upload event was monitored. How to solve it?

Mar.03,2021

https://jsfiddle.net/hfhan/dg.

I just tried the example of the official website. I uploaded two files at a time and ran the callback function twice, so is it your version, or do you want to ask the fileList in watch to listen only once?

in addition

this.fileList = []
if (Array.isArray(fileList)) {
    fileList.forEach((item) => {
        this.fileList.push(item)
    })
}
this.fileList = fileList

what you write in this pile is meaningless

this.fileList = fileList

just write it this way


my version is 2.11.0. The effect I want to achieve is to do my own business operations only after all files have been uploaded successfully.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c0ec-2b647.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c0ec-2b647.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?