这是我在render方法中用于登录用户的表单。
<form onSubmit={this.handleSubmit}>
<Avatar classname={classes.avatar}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<TextField variant="outlined" margin="normal" fullWidth id="email" label="Email Address" name="email"
onChange={this.handleEmailChange}
/>
<TextField variant="outlined" margin="normal" fullWidth
name="password" onChange={this.handlePasswordChange}
/>
{loginError && (
<Typography component="p" classname={classes.errorText}>
Incorrect email or password.
</Typography>
)}
<Button type="button" fullWidth variant="contained" color="primary" classname={classes.submit}
onClick={this.handleSubmit} >
Sign In
</Button>
</form>
以下是我的句柄提交方法
handleSubmit = () => {
const { dispatch } = this.props;
const { email,password } = this.state;
dispatch(loginUser(email,password));
};
在单击按钮时提交有效,但在Enter键上无效。请注意,我正在使用import Button from "@material-ui/core/Button";