Second use of input file doesn't trigger onchange anymore

前端 未结 8 1429
旧巷少年郎
旧巷少年郎 2020-12-25 11:55

I have a picture upload button that automatically uploads the file when selected from the browse window.
Nonetheless, it doesn\'t work the second time around and that is

8条回答
  •  别那么骄傲
    2020-12-25 12:44

    If you're using React or just javascript in general you can what you can also do is "reset" the value of the event target.

    So If you have something like a component that can upload and "remove" an image:

    
    

    your onChange can be:

    onChange(event) {
    
        const files = event.target.files;
    
        // your logic here on what to do with files (maybe fetch the preview or something)
    
        // this line right below will reset the 
        // input field so if you removed it you can re-add the same file
        event.target.value = ''
    }
    

提交回复
热议问题