baiyaaaaa пре 8 година
родитељ
комит
a87b6e2e94

+ 1 - 0
examples/docs/en-US/upload.md

@@ -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 |

+ 1 - 0
examples/docs/zh-CN/upload.md

@@ -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
 | 方法名      | 说明          | 参数 |

+ 1 - 4
packages/upload/src/ajax.js

@@ -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;
 }

+ 4 - 2
packages/upload/src/index.vue

@@ -85,7 +85,8 @@ export default {
     listType: {
       type: String,
       default: 'text'   // text,picture,picture-card
-    }
+    },
+    httpRequest: Function
   },
 
   data() {
@@ -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'
     };

+ 4 - 2
packages/upload/src/upload.vue

@@ -37,7 +37,8 @@ export default {
     },
     fileList: Array,
     autoUpload: Boolean,
-    listType: String
+    listType: String,
+    httpRequest: Function
   },
 
   data() {
@@ -93,7 +94,8 @@ export default {
       }
     },
     post(rawFile) {
-      ajax({
+      const request = this.httpRequest || ajax;
+      request({
         headers: this.headers,
         withCredentials: this.withCredentials,
         file: rawFile,