React开发之入门
2022-12-15 本文已影响0人
Hamiltonian
React开发之入门
A. 创建对象时:new,
B.this 指向属性、指向函数方法
C.Constructor 方法可选,里面bind绑定函数this
constructor(props) {
super(props);
this.state = {date: new Date(),count:0,store:this.props.store};
this.addPrice = this.addPrice.bind(this);
this.addAmount = this.addAmount.bind(this);
}
D.State 负责管理函数内部状态【可读写】,props 负责接收从父控件传入的参数【只读】
this.props.myDataProp
<Content myDataProp = {value}
updateStateProp = {this.handleChange}></Content>
this.state = {value: 'Hello Runoob!'};
this.setState({value: event.target.value});