我與反應工作,並以下教程表單提交了一把,我碰上我的控制檯這個問題:獲取一個event.preventDefault();不是一個功能。爲什麼它不是一個功能?
contact.js:67 Uncaught TypeError: event.preventDefault is not a function(…)
這裏是我的代碼:
contact.js
class ContactForm extends Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
this.state = { open: false };
}
handleSubmit(event) {
console.log('hello');
event.preventDefault();
}
handleTouchTap =() => {
this.setState({ open: true });
}
handleRequestClose =() => {
this.setState({ open: false });
}
render() {
return(
<div>
<Paper className="Form" zDepth={2}>
<Formsy.Form onSubmit={this.handleSubmit}>
<FormsyText
name="Enter Name"
floatingLabelText="Enter your name"
/>
<FormsyText
name="Enter email address"
floatingLabelText="Enter your email address"
/>
<FormsyText
name="message"
floatingLabelText="What can I do for you?"
/>
<RaisedButton onTouchTap={this.handleTouchTap}
type="submit"
label="Submit your message"
primary={true}
/>
<Snackbar
open={this.state.open}
message="Thank your for submitting your message. I'll get back to you as soon as I can!"
autoHideDuration={2000}
onRequestClose={this.handleRequestClose}
/>
</Formsy.Form>
</Paper>
</div>
);
}
}
export { ContactForm };
正如你可以看到我的代碼和我所知道的,我已經正確地將handleSubmit
綁定到我的ContactForm
,並且應該在onSubmit
處理程序上正確調用它this.handleSubmit
。我在這裏可能會錯過什麼?