Skip to content

Commit

Permalink
fix(upload): 修复进度条引起跨域导致文件上传失败问题
Browse files Browse the repository at this point in the history
由于WEB后端配置CORS未处理OPTION,upload进度条效果引起跨域导致文件上传失败,故增加隐藏进度条选项来解决:onProgress() {return false} 即可
  • Loading branch information
gxdvip committed Aug 24, 2021
1 parent a87ce4b commit 8a4149f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/upload/src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function upload(option) {
const xhr = new XMLHttpRequest();
const action = option.action;

if (xhr.upload) {
if (xhr.upload && option.onProgress(false) !== false) {
xhr.upload.onprogress = function progress(e) {
if (e.total > 0) {
e.percent = e.loaded / e.total * 100;
Expand Down
12 changes: 8 additions & 4 deletions packages/upload/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ export default {
this.onChange(file, this.uploadFiles);
},
handleProgress(ev, rawFile) {
const file = this.getFile(rawFile);
this.onProgress(ev, file, this.uploadFiles);
file.status = 'uploading';
file.percentage = ev.percent || 0;
if (ev === false) {
return this.onProgress();
} else {
const file = this.getFile(rawFile);
this.onProgress(ev, file, this.uploadFiles);
file.status = 'uploading';
file.percentage = ev.percent || 0;
}
},
handleSuccess(res, rawFile) {
const file = this.getFile(rawFile);
Expand Down
2 changes: 1 addition & 1 deletion packages/upload/src/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default {
filename: this.name,
action: this.action,
onProgress: e => {
this.onProgress(e, rawFile);
return this.onProgress(e, rawFile);
},
onSuccess: res => {
this.onSuccess(res, rawFile);
Expand Down

0 comments on commit 8a4149f

Please sign in to comment.