(I am using Vue 3) I have a functionality where I add files from an input file to an array, and then conditionally render these file names. Everything works perfectly on Chrome, but I encountered an issue with Mozilla Firefox. In Firefox, the array of files gets overridden by the last added file. For example:
- add file-1 || output: file-1
- add file-1 and then file-2 || output: file-1 file-1 (duplication).
If you'd like to view and test the code, you can do so here: https://codesandbox.io/s/elegant-poitras-exux2z?file=/src/App.vue
method:
methods: {
addFile (file) {
this.form.files.push(file);
}}
Data structure:
data() {
return {
form: {
files: [],
}};},
Output:
<div>
<input @input="addFile($event.target.files)" type="file" name="" id="">
<p v-for="file in form.files" :key="file">
{{ file[0].name }}
</p>
</div>