Javascript 未处理的拒绝(TypeError):无法读取属性';答复';未定义的
如果我的登录凭据错误,我将收到此错误无法读取未定义的属性“response”。如果凭据正确,它将成功登录。有人能帮我吗 Handle Login.js我从错误函数中得到这个Javascript 未处理的拒绝(TypeError):无法读取属性';答复';未定义的,javascript,reactjs,Javascript,Reactjs,如果我的登录凭据错误,我将收到此错误无法读取未定义的属性“response”。如果凭据正确,它将成功登录。有人能帮我吗 Handle Login.js我从错误函数中得到这个 //Handle Login.js handleLogin(e) { e.preventDefault(); this.setState({ message: "", loading: true });
//Handle Login.js
handleLogin(e) {
e.preventDefault();
this.setState({
message: "",
loading: true
});
this.form.validateAll();
if (this.checkBtn.context._errors.length === 0) {
AuthService.login(this.state.email, this.state.password)
.then(
() => {
this.props.history.push("/home");
window.location.reload();
},
error => {
const resMessage =
(error.response && error.response.data && error.response.data.message) || error.message || error.toString();
this.setState({
loading: false,
message: resMessage
});
}
);
} else {
this.setState({
loading: false
});
}
}
Authservice.js
login(username, password) {
return axios.post(API_URL + "signin",
{
username,
password
},
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json-patch+json'
}
})
.then(response => {
if (response.data && response.data.data && response.data.data.token) {
console.log(response.data.message)
localStorage.setItem("user", JSON.stringify(response.data));
return response.data;
}
});
}