【React】react學習筆記12-記錄箭頭函數的傳值方法


import React,{Component} from 'react';

export default class Main extends Component{
constructor(props){
super(props);
this.state={
num:0
}
}
// 在回調函數中使用箭頭函數,可添加參數
getName(name){
console.log(name);
}
getName2=(name)=>{
console.log(name);
}

render() {
let val = 'YY';
let test = 'XX';

return (
<div>
<button onClick={this.getName.bind(this,test) }>getName</button>

<button onClick={
() => {
this.getName2(test)
}
}>getName2</button>

</div>
)
}

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM