这里有很多这样的例子,但似乎无法找到任何反应.我设法转换香草js作出反应,但得到一个错误.
答案看起来很简单所以我在这里做出反应:
getInitialState: function(){
return{file: []}
},
_onChange: function(){
// Assuming only image
var file = this.refs.file.files[0];
var reader = new FileReader();
var url = reader.readAsDataURL(file);
console.log(url) // Would see a path?
// TODO: concat files for setState
},
render: function(){
return(
<div>
<form>
<input
ref="file"
type="file"
name="user[image]"
multiple="true"
onChange={this._onChange}/>
</form>
{/* Only show first image, for now. */}
<img src={this.state.file[0} />
</div>
)
};
Run Code Online (Sandbox Code Playgroud)
基本上我见过的所有答案都显示了我所拥有的东西.React应用程序有何不同?
关于答案: