[英]What is the error in this code of react? When i call the function in part 1 it doesnt work but part 2 works
这是我的代码。 当我在第 1 部分中使用 function 时,它在控制台上没有显示任何内容。 但是当我在第 2 部分中使用 function 时,它显示“你好”。 但我看不出有什么不同。 我在第 1 部分做错了什么?
handleChange = (e) => {
this.setState({
[e.target.id]:e.target.value
})
}
// part 1
handleSubmit = (e) => {
e.prevendDefault()
console.log(this.state)
console.log("hello")
}
// part 2
handleSubmit = (e) => {
e.preventDefault();
console.log(this.state)
console.log('hello')
}
render() {
return (
<div className="form-group container w-50">
<form onSubmit={this.handleSubmit}>
<label htmlFor="">Email</label>
<input type="email" id="email"className="form-control" onChange={this.handleChange} />
<label htmlFor="">Password</label>
<input type="password" id="password" className="form-control" onChange={this.handleChange}/>
<button type="submit" className="btn btn-primary" >Submit</button>
</form>
</div>
);
}
有一个拼写错误
handleSubmit = (e) => {
e.prevendDefault()
console.log(this.state)
console.log("hello")
}
它是preventDefault()
但你有prevendDefault
。
我建议使用 IDE 或具有IntelliSense
或自动完成功能的编辑器,以防止将来出现此类错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.