Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react 事件绑定 #22

Open
RachelRen opened this issue Oct 14, 2018 · 0 comments
Open

react 事件绑定 #22

RachelRen opened this issue Oct 14, 2018 · 0 comments

Comments

@RachelRen
Copy link
Owner

  1. 在函数定义的时候直接bind, 能获取到数据
<button onClick={this.clickHandle.bind(this,"test")}><button>

clickHandle(arg, e){
	
}
  1. 在构造函数内声明, 不能传参数

  2. 箭头函数, 但是都不能传参数

    <button onClick={this.btn2Click}>button 2</button>
    <button onClick={(e) => this.btn3Click(e)}>button 3</button>
    
    btn2Click = (e) => {
    	debugger;
    }
    
    btn3Click(e){
    	debugger;
    }
    
  3. 使用高阶函数

    <button onClick={this.btn5Click("test")}>button 5</button>
    
    btn5Click = name => e =>{
     	debugger;
     }
    

事件机制

源码看React 事件机制

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant