首先我们需要明白
什么是单向数据流?
你通过onClick触发一个动作,再通过函数/类方法修改组件的state,最后通过render()方法再次运行来更新界面
class App extends Component{}不能完成this的自绑定,所以采用以下方式
官方推荐的方法
this.onClickMe = this.onClickMe.bind(this);
有参数时:
onClick={()=>{this.onClickMe(1)}}
无参数时:
onClick={this.onClickMe}
箭头函数类方法
onClickMe= () => {console.log(this);}
通过箭头函数的特性,this绑定组件实例