mirror of https://github.com/ElemeFE/element
add custom http requrest
parent
4ac6fed6a5
commit
a87b6e2e94
|
@ -364,6 +364,7 @@ thumbnail-mode | whether thumbnail is displayed | boolean | — | false
|
||||||
file-list | default uploaded files, i.e: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}] | array | — | []
|
file-list | default uploaded files, i.e: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}] | array | — | []
|
||||||
list-type | type of fileList | string | text/picture/picture-card | text |
|
list-type | type of fileList | string | text/picture/picture-card | text |
|
||||||
auto-upload | whether to auto upload file | boolean | — | true |
|
auto-upload | whether to auto upload file | boolean | — | true |
|
||||||
|
http-request | override default xhr behavior, allowing you to implement your own upload-file's request | function | — | — |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
| Event Name | Description | Parameters |
|
| Event Name | Description | Parameters |
|
||||||
|
|
|
@ -413,6 +413,7 @@
|
||||||
| list-type | 文件列表的类型 | string | text/picture/picture-card | text |
|
| list-type | 文件列表的类型 | string | text/picture/picture-card | text |
|
||||||
| auto-upload | 是否在选取文件后立即进行上传 | boolean | — | true |
|
| auto-upload | 是否在选取文件后立即进行上传 | boolean | — | true |
|
||||||
| file-list | 上传的文件列表, 例如: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}] | array | — | [] |
|
| file-list | 上传的文件列表, 例如: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}] | array | — | [] |
|
||||||
|
| http-request | 覆盖默认的上传行为,可以自定义上传的实现 | function | — | — |
|
||||||
|
|
||||||
### Methods
|
### Methods
|
||||||
| 方法名 | 说明 | 参数 |
|
| 方法名 | 说明 | 参数 |
|
||||||
|
|
|
@ -75,14 +75,11 @@ export default function upload(option) {
|
||||||
|
|
||||||
const headers = option.headers || {};
|
const headers = option.headers || {};
|
||||||
|
|
||||||
// if (headers['X-Requested-With'] !== null) {
|
|
||||||
// xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
||||||
// }
|
|
||||||
|
|
||||||
for (let item in headers) {
|
for (let item in headers) {
|
||||||
if (headers.hasOwnProperty(item) && headers[item] !== null) {
|
if (headers.hasOwnProperty(item) && headers[item] !== null) {
|
||||||
xhr.setRequestHeader(item, headers[item]);
|
xhr.setRequestHeader(item, headers[item]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
|
return xhr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,8 @@ export default {
|
||||||
listType: {
|
listType: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'text' // text,picture,picture-card
|
default: 'text' // text,picture,picture-card
|
||||||
}
|
},
|
||||||
|
httpRequest: Function
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
@ -228,7 +229,8 @@ export default {
|
||||||
'on-success': this.handleSuccess,
|
'on-success': this.handleSuccess,
|
||||||
'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
|
||||||
},
|
},
|
||||||
ref: 'upload-inner'
|
ref: 'upload-inner'
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,8 @@ export default {
|
||||||
},
|
},
|
||||||
fileList: Array,
|
fileList: Array,
|
||||||
autoUpload: Boolean,
|
autoUpload: Boolean,
|
||||||
listType: String
|
listType: String,
|
||||||
|
httpRequest: Function
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
@ -93,7 +94,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
post(rawFile) {
|
post(rawFile) {
|
||||||
ajax({
|
const request = this.httpRequest || ajax;
|
||||||
|
request({
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
withCredentials: this.withCredentials,
|
withCredentials: this.withCredentials,
|
||||||
file: rawFile,
|
file: rawFile,
|
||||||
|
|
Loading…
Reference in New Issue