如何从输入中读取文件并保存为React状态

时间:2018-10-11 19:20:33

标签: javascript reactjs react-redux redux-saga

我现在正在从事React和Redux项目。我想要实现的是从输入区域读取文件,并将状态另存为文件,然后使用动作和传奇通过HTTP请求传递它。

state={
    file: {}
};
<Input 
      type="file"
      accept="image/*"
      onChange={(e) => {
          let file = e.target.files[0];
          console.log(file);
          this.setState({file: file})}});
      }}
>
</Input>

但这不起作用。有想法吗?

It gave error of this when I tried to see it in the React inspect. 
backend.js:7715 Uncaught TypeError: Illegal invocation
    at backend.js:7715
    at Array.forEach (<anonymous>)
    at Bridge._inspectResponse (backend.js:7711)
    at Bridge._handleMessage (backend.js:7592)
    at listener (backend.js:92)

0 个答案:

没有答案