Skip to content

Commit a17e543

Browse files
committed
1 parent 49bdabc commit a17e543

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

dist/vue-upload-drop-images.vue

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,27 @@ export default {
2222
dragLeave() {},
2323
drop(e) {
2424
let status = true;
25-
26-
e.dataTransfer.files.forEach((file) => {
27-
if (file.type.startsWith("image") === false) status = false;
28-
});
29-
if (status == true) {
30-
if (
31-
this.$props.max &&
32-
e.dataTransfer.files.length + this.files.length > this.$props.max
33-
) {
34-
this.error = this.$props.maxError
35-
? this.$props.maxError
36-
: `Maximum files is` + this.$props.max;
25+
if (e && e.dataTransfer.files) {
26+
e.dataTransfer.files.forEach((file) => {
27+
if (file.type.startsWith("image") === false) status = false;
28+
});
29+
if (status == true) {
30+
if (
31+
this.$props.max &&
32+
e.dataTransfer.files.length + this.files.length > this.$props.max
33+
) {
34+
this.error = this.$props.maxError
35+
? this.$props.maxError
36+
: `Maximum files is` + this.$props.max;
37+
} else {
38+
this.files.push(...e.dataTransfer.files);
39+
this.previewImgs();
40+
}
3741
} else {
38-
this.files.push(...e.dataTransfer.files);
39-
this.previewImgs();
42+
this.error = this.$props.fileError
43+
? this.$props.fileError
44+
: `Unsupported file type`;
4045
}
41-
} else {
42-
this.error = this.$props.fileError
43-
? this.$props.fileError
44-
: `Unsupported file type`;
4546
}
4647
this.dropped = 0;
4748
},
@@ -81,13 +82,10 @@ export default {
8182
this.error = "";
8283
this.$emit("change", this.files);
8384
let readers = [];
84-
8585
if (!this.files.length) return;
86-
8786
for (let i = 0; i < this.files.length; i++) {
8887
readers.push(this.readAsDataURL(this.files[i]));
8988
}
90-
9189
Promise.all(readers).then((values) => {
9290
this.Imgs = values;
9391
});
@@ -108,6 +106,7 @@ export default {
108106
<div v-show="error" class="error">
109107
{{ error }}
110108
</div>
109+
111110
<!-- To inform user how to upload image -->
112111
<div v-show="Imgs.length == 0" class="beforeUpload">
113112
<input
@@ -305,7 +304,6 @@ export default {
305304
width: 100%;
306305
height: 100%;
307306
}
308-
309307
.imgsPreview .imageHolder .delete {
310308
position: absolute;
311309
top: 4px;
@@ -342,4 +340,4 @@ export default {
342340
.plus:hover {
343341
cursor: pointer;
344342
}
345-
</style>
343+
</style>

0 commit comments

Comments
 (0)