单向数据绑定
1.在constructor里注册数据
constructor(){
super();
this.title="注册"
}
2.使用{}进行数据绑定
<h3>{this.title}</h3>
双向数据绑定
1.在constructor里用this.state注册数据
constructor(){
super();
this.state={
user:"",
pass:"",
loginSuccess:false
}
}
2.使用onChange事件监听数据变化并赋值给this.state
handeChange(item,event){
for(let StateItem in this.state){
if(item===StateItem){
this.state[item]=event.target.value;
this.setState(this.state)
}
}
}
<div className="input-box">
<label htmlFor="" >用户名</label><input type="text" onChange={this.handeChange.bind(this,&