Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VueJS: Input file selection event not firing upon selecting the same file

How can we file input detect change on SAME file input in Vue Js

<input ref="imageUploader" type="file" @change="uploadImageFile">

like image 667
zubair-0 Avatar asked Jan 10 '19 08:01

zubair-0


2 Answers

We can add @click event and then clear the value of the file input

<template>
    ....
        <input ref="imageUploader" type="file" accept=".jpg, .jpeg" @click="resetImageUploader" @change="uploadImageFile">
    ....
</template>

<script>
    export default {
        methods: {
            resetImageUploader() {
                this.$refs.imageUploader.value = '';
            },
            uploadImageFile() {
                ....
            }
        }
    }
</script>
like image 85
zubair-0 Avatar answered Nov 14 '22 23:11

zubair-0


Same thing as @zubair's answer but for vue 3 and a bit more convenient:

<input type="file" @change="renderImage($event)" @click="$event.target.value=''">
like image 2
Artur Müller Romanov Avatar answered Nov 14 '22 21:11

Artur Müller Romanov