当我尝试发出发布请求时,出现网络错误,错误消息为“未定义”
这是设置:
export default axios.create({
baseURL: API_HOST,
withCredentials: true,
crossdomain: true,
});
和实际通话:
export const Login = (email, password) => dispatch => {
axios
.post('/v1/login?', {email, password})
.then(response => {
console.log('yes');
token = () => {
return response.token ? response.token : '';
};
dispatch({
type: UPDATE_AUTH_PROPS,
payload: [
{prop: 'errorMessage', value: 'successed'},
{prop: 'token', value: token},
],
});
})
.catch(error => {
debugger;
dispatch({
type: UPDATE_AUTH_PROPS,
payload: [{prop: 'errorMessage', value: error.message}],
});
});
};
答案 0 :(得分:0)
尝试一下,这很容易阅读...
axios
.post(api_url + '/v1/login?', data, {
'Content-Type': 'application/json',
})
.then(
res => {
alert('Response');
},
error => {
alert('Error');
},
);
}
};