我正在为投资组合构建器使用React应用程序,当我运行它时,我看不到我在输入框中键入的任何内容。有人可以看一下,让我知道为什么吗?非常感谢。谢谢!!我已经正确设置了onChange的大小写,发现它是一个问题,但是我不明白为什么这是行不通的。
class Login extends Component {
constructor() {
super();
this.state = {
email: '',
password: '',
};
}
handleSubmit = (event) => {
event.preventDefault();
//console.log("submit selected");
const userData = {
email: this.state.email,
password: this.state.password
};
this.props.loginUser(userData, this.props.history);
};
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value
});
};
render() {
return (
<div className = "sign-in">
<Topbar />
<form onSubmit={this.handleSubmit}>
<input
type = "text"
placeholder="Email"
value={this.state.email}
onChange = {this.handleChange}
/>
<input
type = "password"
placeholder= "Password"
value={this.state.password}
onChange = {this.handleChange}
/>
<button type = "submit"> Sign In </button>
</form>
</div>
);
}
}
答案 0 :(得分:0)
在handleChange上,您从目标的名称获取状态,但是目标没有名称(以html输入)