Skip to content

Commit

Permalink
add custom http requrest
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyaaaaa authored and Leopoldthecoder committed Mar 9, 2017
1 parent 4ac6fed commit a87b6e2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/docs/en-US/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | — | []
list-type | type of fileList | string | text/picture/picture-card | text |
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
| Event Name | Description | Parameters |
Expand Down
1 change: 1 addition & 0 deletions examples/docs/zh-CN/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
| list-type | 文件列表的类型 | string | text/picture/picture-card | text |
| 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 || [] |
| http-request | 覆盖默认的上传行为,可以自定义上传的实现 | function |||

### Methods
| 方法名 | 说明 | 参数 |
Expand Down
5 changes: 1 addition & 4 deletions packages/upload/src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ export default function upload(option) {

const headers = option.headers || {};

// if (headers['X-Requested-With'] !== null) {
// xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
// }

for (let item in headers) {
if (headers.hasOwnProperty(item) && headers[item] !== null) {
xhr.setRequestHeader(item, headers[item]);
}
}
xhr.send(formData);
return xhr;
}
6 changes: 4 additions & 2 deletions packages/upload/src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default {
listType: {
type: String,
default: 'text' // text,picture,picture-card
}
},
httpRequest: Function
},
data() {
Expand Down Expand Up @@ -228,7 +229,8 @@ export default {
'on-success': this.handleSuccess,
'on-error': this.handleError,
'on-preview': this.onPreview,
'on-remove': this.handleRemove
'on-remove': this.handleRemove,
httpRequest: this.httpRequest
},
ref: 'upload-inner'
};
Expand Down
6 changes: 4 additions & 2 deletions packages/upload/src/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default {
},
fileList: Array,
autoUpload: Boolean,
listType: String
listType: String,
httpRequest: Function
},
data() {
Expand Down Expand Up @@ -93,7 +94,8 @@ export default {
}
},
post(rawFile) {
ajax({
const request = this.httpRequest || ajax;
request({
headers: this.headers,
withCredentials: this.withCredentials,
file: rawFile,
Expand Down

0 comments on commit a87b6e2

Please sign in to comment.