标签:绑定 asc .com bind 创建 tcl out this es6
第一种:官方推荐的:
class LoginControl extends React.Component {
constructor(props) {
super(props);
this.handleLoginClick = this.handleLoginClick.bind(this);
this.handleLogoutClick = this.handleLogoutClick.bind(this);
this.state = {isLoggedIn: false};
}
第二种:比较方便
render() {
return (
<div onClick={this.handleClick.bind(this)}>ES6方式创建的组件</div>
);
}
第三种:箭头函数
return (
<button onClick={(e) => this.handleClick(e)}>
Click me
</button>
);
标签:绑定 asc .com bind 创建 tcl out this es6
原文地址:http://www.cnblogs.com/feiying100/p/6649611.html