【发布时间】:2019-10-08 21:28:40
【问题描述】:
如果 status==200 ok,我正在尝试推送到 /home,但它给了我一个错误。
handleSubmit = (e) => {
e.preventDefault();
const form = this.props.form;
const { password, username } = this.state;
let data = new FormData(); // creates a new FormData object
data.append('username', form.getFieldValue('username'));
data.append('password', form.getFieldValue('password'));
axios.post('http://127.0.0.1:8000/user/login/', data)
.then(res=>console.log(res))
.then(data => { if(data.status == 200){ history.push('/home');}})
.catch(err=>console.log(err))
};
它呈现这个:
{data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}
TypeError: 无法读取未定义的属性“状态”
【问题讨论】:
-
你为什么第二次使用.then? axios.post('127.0.0.1:8000/user/login', data) .then(data => { if(data.status == 200){ history.push('/home');}}) .catch(err=>console.日志(错误))。这应该有效。