Add support for httpRequest Promise (#3389)

* Add support for httpRequest Promise

添加支持httpRequest Promise

* fixbug

* fixbug
pull/3948/head
2017-04-01 11:05:27 +08:00 committed by baiyaaaaa
parent eac95e99c4
commit 81ba7084e3
2 changed files with 11 additions and 5 deletions

View File

@ -233,7 +233,7 @@ export default {
'on-error': this.handleError, 'on-error': this.handleError,
'on-preview': this.onPreview, 'on-preview': this.onPreview,
'on-remove': this.handleRemove, 'on-remove': this.handleRemove,
httpRequest: this.httpRequest 'http-request': this.httpRequest
}, },
ref: 'upload-inner' ref: 'upload-inner'
}; };

View File

@ -38,7 +38,10 @@ export default {
fileList: Array, fileList: Array,
autoUpload: Boolean, autoUpload: Boolean,
listType: String, listType: String,
httpRequest: Function httpRequest: {
type: Function,
default: ajax
}
}, },
data() { data() {
@ -92,8 +95,7 @@ export default {
} }
}, },
post(rawFile) { post(rawFile) {
const request = this.httpRequest || ajax; const options = {
request({
headers: this.headers, headers: this.headers,
withCredentials: this.withCredentials, withCredentials: this.withCredentials,
file: rawFile, file: rawFile,
@ -109,7 +111,11 @@ export default {
onError: err => { onError: err => {
this.onError(err, rawFile); this.onError(err, rawFile);
} }
}); };
const requestPromise = this.httpRequest(options);
if (requestPromise && requestPromise.then) {
requestPromise.then(options.onSuccess, options.onError);
}
}, },
handleClick() { handleClick() {
this.$refs.input.click(); this.$refs.input.click();