【发布时间】:2018-11-01 22:57:07
【问题描述】:
每次点击登录按钮时都会出错
TypeError: Cannot read property 'then' of undefined
,但重新加载后错误消失了。我能知道发生了什么吗?这是我的登录代码
onSignIn(e){
e.preventDefault()
this.Auth.login(this.state.signInUsername, this.state.signInPassword)
.then(res => {
this.props.history.replace('/')
})
.catch(err => {
alert(err)
})
}
这是我的授权码:
login(username, password){
axios.post('http://localhost:3000/user/login', {
username,
password
})
.then(this._checkStatus)
.then(res => {
if(res.data.success === true){
const payload = {
name: username,
}
this.setToken(payload)
return Promise.resolve(res)
}else{
console.log(res.data.message)
}
})
.catch(err => {
return Promise.reject(err)
})
}
【问题讨论】:
-
.catch(err => { return Promise.reject(err) })是多余的,放弃吧。
标签: reactjs function promise axios request-promise