如何在 react.js 中使用 refs 从文件类型的 html 输入表单中获取文件数据

How to get the file data from an html input form of type file, using refs in react.js

本文关键字:文件 html 类型 输入 数据 获取 表单 refs react js      更新时间:2023-09-26
<input type="file" ref="file" size="45" />

我想从 MSDN fileInputElement.files[0] 那里得到这样的东西但我这样做ReactDOM.findDOMNode(this.refs.file).files[0] 但没有返回任何数据。

this.refs.file.files[0]

对我有用

<input type="file" name="sendAttachment" 
       ref={(input) => {  this.sendFile  = input; }}
       onChange={  (e)=>{this.sendAttachment(e)  }} />
sendAttachment(e) 
{
  e.preventDefault();
  console.log(this.sendFile.files[0]);
}