Reactjs 预览从材质ui中的库中为react选择的图像
我正在尝试制作一个上传按钮来上传图像。在提交之前,我想在选择图像后立即显示它 我正在使用材质ui库进行react。下面是我尝试过的,但是一旦我选择了一个新的图像,图像元素就会从DOM中被销毁Reactjs 预览从材质ui中的库中为react选择的图像,reactjs,image,material-ui,Reactjs,Image,Material Ui,我正在尝试制作一个上传按钮来上传图像。在提交之前,我想在选择图像后立即显示它 我正在使用材质ui库进行react。下面是我尝试过的,但是一旦我选择了一个新的图像,图像元素就会从DOM中被销毁 constructor(props){ super(props); this.state={ newImage:'https://seeklogo.com/images/I/instagram-new-2016-logo-4773FE3F99-seeklogo.com.png
constructor(props){
super(props);
this.state={
newImage:'https://seeklogo.com/images/I/instagram-new-2016-logo-4773FE3F99-seeklogo.com.png',
}
}
。
.
在这里找到了答案:
<Avatar
alt="Selected Image"
src={this.state.newImage}
className={classes.bigAvatar}
/>
<RaisedButton
<input
type="file"
onChange = {(event,newValue) => this.setState({newImage:newValue})}
/>
</RaisedButton>