From 5dcfb423dd1073557c1d58dde367ecb173b63f26 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Tue, 11 Oct 2022 20:40:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20support=20httpRequest=20?= =?UTF-8?q?promise=20for=20upload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #1100 --- src/components/upload/upload.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/upload/upload.vue b/src/components/upload/upload.vue index cc9312462..2acf422c0 100644 --- a/src/components/upload/upload.vue +++ b/src/components/upload/upload.vue @@ -147,7 +147,11 @@ webkitdirectory: { type: Boolean, default: false - } + }, + httpRequest: { + type: Function, + default: ajax + }, }, data () { return { @@ -250,7 +254,7 @@ let formData = new FormData(); formData.append(this.name, file); - ajax({ + const options = { headers: this.headers, withCredentials: this.withCredentials, file: file, @@ -266,7 +270,11 @@ onError: (err, response) => { this.handleError(err, response, file); } - }); + }; + const req = this.httpRequest(options); + if (req && req.then) { + req.then(options.onSuccess, options.onError); + } }, handleStart (file) { file.uid = Date.now() + this.tempIndex++;