【发布时间】:2018-10-20 17:51:31
【问题描述】:
我们可以在 React js style={style} 中实现这一点吗??
constructor(props) {
super(props);
this.state = {
style_title: {"color": "blue"}
};
this.change = this.change.bind(this);
}
change(e) {
this.setState({
[e.target.name]: e.target.value })
}
我的表单:
<input type="text" name="title" value={this.props.title} onChange={e =>this.changeEdit(e)} />
<input type="text" name="style_title" value={this.props.style_title} onChange={e =>this.changeEdit(e)} />
在预览模式下打印标题文本为此我需要使用输入字段动态设置标题样式,例如:
{ "color": "blue", "font-size": "22px",}
以上样式应在样式属性中应用渲染<p style={style}>{this.props.title }</p>
预览部分:
render = () => (
const style = this.props.style_title;
return (
<p style={style}>{this.props.title }</p>
);
)
【问题讨论】:
-
你的问题需要解释你写的更多,你的愿望有点不清楚,你的意思是,你想要一个表单来获取样式并将其实现到另一个组件?
-
是的,一旦我点击提交值应该更新 this.state {title:"",custom_css:""}
标签: reactjs