【发布时间】:2016-10-18 23:01:32
【问题描述】:
我正在尝试创建一个背景图像更新器/上传器组件。
图像是默认设置的,但是,如果用户想更新背景图像,我想更新状态并存储图像。
到目前为止的研究表明我需要使用<input type="file" /> 元素来启用上传对话框。
还有其他不使用输入元素的方法吗?如果用户要单击<button> 元素以显示对话框,然后更新背景图像。
export default class ChangeBackground extends React.Component {
constructor() {
super();
this.state = {
backgroundImage: ''
}
}
handleBackgroundChange() {
let backgroundImage = backgroundImage
this.setState({
backgroundImage: backgroundImage
});
}
render() {
return (
<div className="change-bg-wrap">
<input type="file" accept="image/*" />
<button>
<i className="fa fa-picture-o" style={{fontSize: 20}}></i>
</button>
</div>
)
}
}
【问题讨论】:
标签: javascript reactjs image-uploading