1

I am new in vue and i want to display files after they dropped the file area. So far, i can took files and i can display them when they dropped file area in once. When i try to add another file, previous files disappearing because i am just assigning event files to input every time just like that :

this.$refs.file.files = e.dataTransfer.files;

So i believe if i can push the event files to input every time when dropped file, problem will solve.

So far i tried that but it's giving push is not a function error.

this.$refs.file.files.push(e.dataTransfer.files);

Sorry if you didn't understand me i can explain more. Can someone help me about it?

<input type="file" name="file" id="file" multiple ref="file" style="display:none;"
         v-on:change="handleFileUpload()"/>

handleFileUpload Method:

 handleFileUpload(e = null) {
this.$refs.file.files.push(e.dataTransfer.files);
 for (let i = 0; i < this.$refs.file.files.length; i++) {
        const reader = new FileReader();
        reader.addEventListener('load', (event) => {
          this.$refs.image[i].src = event.target.result
        }, false);
        reader.readAsDataURL(this.$refs.file.files[i]);
        this.dragleave(e)
      }}
Atif Şeşu
  • 125
  • 11
  • Are you doing this `ref="file"` on a `v-for` loop? – Yom T. Nov 02 '20 at 09:51
  • I edited question – Atif Şeşu Nov 02 '20 at 10:28
  • 1
    Well, [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList) doesn't have a setter method like the native array does. To work around this, you could reassign it to fresh items with the wanted one appended, see [this post](https://stackoverflow.com/a/52079109/3634538) for an example. – Yom T. Nov 02 '20 at 11:08

0 Answers0