Second use of input file doesn't trigger onchange anymore

前端 未结 8 1435
旧巷少年郎
旧巷少年郎 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:34

    After you have done what you want to do with the file, you can reset the FileList.

    In my React app I have this:

    const handleLoad = evt => {
      if (evt.target.files && evt.target.files[0]) {
        dispatch(loadFile(evt.target.files[0].path));
      }
      // Reset the FileList, as otherwise the second and subsequent times
      // we browse, nothing will happen, because nothing changed.
      evt.target.files = new FileList();
    };
    

提交回复
热议问题