Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

文件上传组件,取消文件上传时终止ajax传输;暴露xhr对象在文件列表里面 #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/upload/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ export default function upload(option) {
}
}
xhr.send(formData);

return xhr;
}
10 changes: 8 additions & 2 deletions src/components/upload/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@
}
}

this.handleStart(file);
const _file = this.handleStart(file);
let formData = new FormData();
formData.append(this.name, file);

ajax({
_file.xhr = ajax({
headers: this.headers,
withCredentials: this.withCredentials,
file: file,
Expand Down Expand Up @@ -274,6 +274,8 @@
};

this.fileList.push(_file);

return _file;
},
getFile (file) {
const fileList = this.fileList;
Expand Down Expand Up @@ -316,6 +318,7 @@
},
handleRemove(file) {
const fileList = this.fileList;
file.xhr.abort();
fileList.splice(fileList.indexOf(file), 1);
this.onRemove(file, fileList);
},
Expand All @@ -325,6 +328,9 @@
}
},
clearFiles() {
this.fileList.forEach(file => {
file.xhr.abort();
});
this.fileList = [];
}
},
Expand Down