方式一:传统
import React, { Component } from 'react'; class App extends Component {
handleSubmit (e, args) {
console.log(e, args)
} render () {
return (
<div onClick={this.handleSubmit.bind(this, 'test')}>test</div>
)
}
}
2、es6 箭头函数
import React, { Component } from 'react'; class App extends Component {
handleSubmit = (e) => {
console.log(e);
} render () {
return (
<div onClick={this.handleSubmit}>test</div>
)
}
}
// 或者 import React, { Component } from 'react'; class App extends Component {
handleSubmit (e) {
console.log(e);
} render () {
return (
<div onClick={ () => this.handleSubmit }>test</div>
)
}
}