From 3c2f68f215ef1e3c4a2b15e85454374184076883 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Sun, 22 Jan 2017 18:08:36 +0800 Subject: [PATCH] update Upload --- src/components/upload/upload.vue | 4 ++-- test/routers/upload.vue | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/upload/upload.vue b/src/components/upload/upload.vue index 8f948bc..89d3b58 100644 --- a/src/components/upload/upload.vue +++ b/src/components/upload/upload.vue @@ -207,7 +207,7 @@ const _file_format = file.name.split('.').pop().toLocaleLowerCase(); const checked = this.format.some(item => item.toLocaleLowerCase() === _file_format); if (!checked) { - this.onFormatError(file); + this.onFormatError(file, this.fileList); return false; } } @@ -215,7 +215,7 @@ // check maxSize if (this.maxSize) { if (file.size > this.maxSize * 1024) { - this.onExceededSize(file); + this.onExceededSize(file, this.fileList); return false; } } diff --git a/test/routers/upload.vue b/test/routers/upload.vue index b07ae16..0ecfa95 100644 --- a/test/routers/upload.vue +++ b/test/routers/upload.vue @@ -20,6 +20,7 @@ :max-size="2048" :on-format-error="handleFormatError" :on-exceeded-size="handleMaxSize" + :before-upload="handleBeforeUpload" multiple type="drag" action="//jsonplaceholder.typicode.com/posts/" @@ -81,6 +82,15 @@ title: '超出文件大小限制', desc: '文件 ' + file.name + ' 太大,不能超过 2M。' }); + }, + handleBeforeUpload () { + const check = this.uploadList.length < 5; + if (!check) { + this.$Notice.warning({ + title: '最多只能上传 5 张图片。' + }); + } + return check; } } } -- libgit2 0.21.4