当从 API 返回 401 时,我想在组件中显示错误消息。我正在尝试使用不受任何约束的状态并且正在使用 ES6。我正进入(状态
Cannot read property 'setState' of undefined
这是登录功能:
login(e) {
e.preventDefault();
AuthService.login(this.state.username, this.state.password)
.catch(function (err) {
console.log(err);
this.setState({loginFailed: true});
});
}