react 事件绑定的2种常用方式

方式一:传统

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>
)
}
}
上一篇:CodeForces 719A. Vitya in the Countryside


下一篇:.NET MVC扩展UrlHelper支持CDN