【React】react学习笔记12-记录箭头函数的传值方法

class App extends React.Component {
  constructor() {
  }
  
  // 在回调函数中使用箭头函数,可添加参数
  getName(name) {
    console.log(name);
  }
  
  render() {
    let name = 'RR';
    return (
      <>
        <button onClick={(name) => { this.getName(name) }}>姓名</button>
        //
        <button onClick={function(name){ this.getName(name) }}>姓名</button>
      </>
    )
  }
}

猜你喜欢

转载自www.cnblogs.com/the-fool/p/11232558.html