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>
)
}
}