Skip to content

Commit 31e0617

Browse files
author
kenberkeley
committed
MsgForm submit preventDefault
1 parent c46b938 commit 31e0617

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/components/Msg/MsgForm/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export default class MsgForm extends Component {
7979
}
8080

8181
/* 同样地,提交表单前需要根据当前 mode 进行对应的操作 */
82-
handleSubmit () {
82+
handleSubmit (evt) {
83+
evt.preventDefault()
8384
let { pathname } = this.props.location
8485
let opt = isAddMode(pathname) ? 'addMsg' : 'modMsg'
8586

src/components/Msg/MsgForm/msg-form.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react'
99
// (因为箭头函数没有自己的 this!无法通过 call/apply 改变)
1010
export default function () {
1111
return (
12-
<form>
12+
<form onSubmit={(e) => this.handleSubmit(e)}>
1313
<div className="form-group">
1414
<label htmlFor="title">标题</label>
1515
<input
@@ -45,9 +45,8 @@ export default function () {
4545
</div>
4646
<div className="btn-group" role="group">
4747
<button
48-
type="button"
49-
className="btn btn-success"
50-
onClick={() => this.handleSubmit()}>
48+
type="submit"
49+
className="btn btn-success">
5150
提交&nbsp;
5251
<span className="glyphicon glyphicon-ok"></span>
5352
</button>

0 commit comments

Comments
 (0)