vue-upload-component
vue-upload-component copied to clipboard
On-Complete Action
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
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 Sorry but this stops the crop Feature (editing) on avatar.vue
Thanks
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)
}
}
}
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()
}
}
}