mirror of https://github.com/ElemeFE/element
Add support for httpRequest Promise (#3389)
* Add support for httpRequest Promise 添加支持httpRequest Promise * fixbug * fixbugpull/3948/head
parent
eac95e99c4
commit
81ba7084e3
|
@ -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'
|
||||||
};
|
};
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue