Commit 3c2f68f215ef1e3c4a2b15e85454374184076883
1 parent
a6ac0a76
update Upload
update Upload
Showing
2 changed files
with
12 additions
and
2 deletions
Show diff stats
src/components/upload/upload.vue
... | ... | @@ -207,7 +207,7 @@ |
207 | 207 | const _file_format = file.name.split('.').pop().toLocaleLowerCase(); |
208 | 208 | const checked = this.format.some(item => item.toLocaleLowerCase() === _file_format); |
209 | 209 | if (!checked) { |
210 | - this.onFormatError(file); | |
210 | + this.onFormatError(file, this.fileList); | |
211 | 211 | return false; |
212 | 212 | } |
213 | 213 | } |
... | ... | @@ -215,7 +215,7 @@ |
215 | 215 | // check maxSize |
216 | 216 | if (this.maxSize) { |
217 | 217 | if (file.size > this.maxSize * 1024) { |
218 | - this.onExceededSize(file); | |
218 | + this.onExceededSize(file, this.fileList); | |
219 | 219 | return false; |
220 | 220 | } |
221 | 221 | } | ... | ... |
test/routers/upload.vue
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 | :max-size="2048" |
21 | 21 | :on-format-error="handleFormatError" |
22 | 22 | :on-exceeded-size="handleMaxSize" |
23 | + :before-upload="handleBeforeUpload" | |
23 | 24 | multiple |
24 | 25 | type="drag" |
25 | 26 | action="//jsonplaceholder.typicode.com/posts/" |
... | ... | @@ -81,6 +82,15 @@ |
81 | 82 | title: '超出文件大小限制', |
82 | 83 | desc: '文件 ' + file.name + ' 太大,不能超过 2M。' |
83 | 84 | }); |
85 | + }, | |
86 | + handleBeforeUpload () { | |
87 | + const check = this.uploadList.length < 5; | |
88 | + if (!check) { | |
89 | + this.$Notice.warning({ | |
90 | + title: '最多只能上传 5 张图片。' | |
91 | + }); | |
92 | + } | |
93 | + return check; | |
84 | 94 | } |
85 | 95 | } |
86 | 96 | } | ... | ... |