vue-upload-component icon indicating copy to clipboard operation
vue-upload-component copied to clipboard

On-Complete Action

Open mzubairharoon opened this issue 6 years ago • 4 comments

Hi, can you please tell in this avatar.vue what is the on-complete method, the JSON we receive from the server, I don't see it anywhere to capture Server Response after saving the crop to Server, I mean XHR response.

https://github.com/lian-yue/vue-upload-component/blob/master/docs/views/examples/Avatar.vue

Thanks

mzubairharoon avatar May 10 '18 07:05 mzubairharoon

        methods: {
            /**
             * Has changed
             * @param  newFile Object|undefined      只读
             * @param  oldFile Object|undefined      只读
             * @return undefined
             */
            inputFile: function (newFile, oldFile) {
                if (newFile && oldFile && !newFile.active && oldFile.active) {
                    // 获得相应数据
                    console.log('response', newFile.response)
                    if (newFile.xhr) {
                        //  获得响应状态码
                        console.log('status', newFile.xhr.status)
                    }
                }
            }
}

you can see console.log('response', newFile.response)

weituotian avatar May 10 '18 13:05 weituotian

@weituotian Sorry but this stops the crop Feature (editing) on avatar.vue

Thanks

mzubairharoon avatar May 10 '18 13:05 mzubairharoon

inputFile(newFile, oldFile, prevent) {
  if (newFile && !oldFile) {
    this.$nextTick(function () {
      this.edit = true
    })
  }
  if (!newFile && oldFile) {
    this.edit = false
  }

  if (newFile && oldFile && !newFile.active && oldFile.active) {
    // 获得相应数据
    console.log('response', newFile.response)
    if (newFile.xhr) {
      //  获得响应状态码
      console.log('status', newFile.xhr.status)
    }
  }
}

lian-yue avatar May 11 '18 05:05 lian-yue

I ended up doing this, the above was a great help. note I used lodash to iterate and sum the result.

      if (newFile && oldFile && !newFile.active && oldFile.active) {
        if (newFile.xhr) {
          //iterate all files and see if all have uploaded successfuly
          var result = _.map(this.$refs.files.value, function(file, index) {
            if (!file.response.success){
              return 1
            }
            return 0
          })
          if (_.sum(result) == 0){//all files are uploaded
            this.$refs.files.clear()
           // The function below updates a file list on my page so when the uploaded files are cleared
          // the file list is updated with the newly uploaded ones.
            this.updateFiles() 
          }
        }
      }

lobonz avatar Aug 29 '19 07:08 lobonz