Browse Source

feat:uploader上传组件支持withCredentials参数 #190

richard1015 6 years ago
parent
commit
8833bf06f2
3 changed files with 8 additions and 1 deletions
  1. 1 0
      src/packages/uploader/doc.md
  2. 5 0
      src/packages/uploader/uploader.vue
  3. 2 1
      src/utils/uploader.js

+ 1 - 0
src/packages/uploader/doc.md

@@ -157,6 +157,7 @@ export default {
 | typeError | 文件类型错误提示文案 | String | "不支持上传该类型文件"
 | limitError | 文件大小超过限制提示文案 | String | "文件大小超过限制"
 | xmlError | 浏览器不支持本组件时的提示文案 | String | "对不起,您的浏览器不支持本组件!"
+| withCredentials | 支持发送 cookie 凭证信息 | Boolean | fasle
 
 ## Event
 

+ 5 - 0
src/packages/uploader/uploader.vue

@@ -71,6 +71,10 @@ export default {
     limitError: {
       type: String,
       default: ''
+    },
+    withCredentials: {
+      type: Boolean,
+      default: false
     }
   },
   data() {
@@ -90,6 +94,7 @@ export default {
         acceptType: this.acceptType, //允许上传的文件类型
         xhrState: this.xhrState,
         clearInput: this.clearInput,
+        withCredentials: this.withCredentials,//支持发送 cookie 凭证信息
         xmlError: this.xmlError || this.nutTranslate('lang.uploader.xmlError'),
         typeError: this.typeError || this.nutTranslate('lang.uploader.typeError'),
         limitError: this.limitError || this.nutTranslate('lang.uploader.limitError'),

+ 2 - 1
src/utils/uploader.js

@@ -5,6 +5,7 @@ class IdaUploader {
            url: '',
            formData: null,
            headers: {}, //自定义headers
+           withCredentials:false,//支持发送 cookie 凭证信息
            isPreview: true, //是否开启本地预览
            previewData: null,
            maxSize: 0, //允许上传的文件最大字节,0为不限制
@@ -92,7 +93,7 @@ class IdaUploader {
                    }
                }
            };
-           xhr.withCredentials = true;
+           xhr.withCredentials = options.withCredentials;
            xhr.open('POST', options.url, true);
            // headers
            for (let key in options.headers) {