Skip to content
Advertisement

How to add files from file input into array in Firefox browser?

(I’m using vue 3) I’m adding files from input file to array, then I conditionally render these file names. All working good on Chrome. Problem is when using Mozilla Firefox. In this browser array of files is overrided by last added file, for example:

  1. add file-1 || output: file-1
  2. add file-1 and next file-2 || output: file-1 file-1 (duplication).

There you can view and test this code: https://codesandbox.io/s/elegant-poitras-exux2z?file=/src/App.vue
method:

JavaScript

data structure:

JavaScript

output:

JavaScript

Advertisement

Answer

Got a fix for you

JavaScript

Reason is – well, my theory is that $event.target.files is not a new object every time addFile($event.target.files) is called

You’ll see this if you change your code to

JavaScript

This logs true in Firefox 103, but false in Firefox 104 (dev version)

Another alternative

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement