Created
July 17, 2017 07:20
Revisions
-
happypeter created this gist
Jul 17, 2017 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 现在来实现表单提交事件的相应,添加 `handleSubmit` 如下 ``` <form onSubmit={this.handleSubmit} className="comment-form"> <input type="text" className="input" /> <button type="submit" className="submit-btn" >提交</button> </form> ``` 名称注释: - Submit 提交 - handle 处理 - form 表单 然后定义 handleSubmit ```js handleSubmit = (e) => { e.preventDefault() console.log('submitting....') } ``` 由于使用了 ES6 的胖箭头函数语法,所以使用中,就不需要 bind(this) 了。 `e.preventDefault()` 的作用是 >在表单提交的时候,阻止页面跳转