【发布时间】:2020-04-14 00:08:24
【问题描述】:
我更改了代码以在一个地方处理 API 错误,但它停止工作,任何人都可以找出问题所在
改变之前(工作正常)
action.js
export const login = (email, password) => dispatch => {
axios
.post('http://localhost:8000/v1/users/signin/', {
email: email,
password: password,
})
.then(res => {
dispatch({
type: LOGIN_USER,
payload: res.data,
});
})
.catch(err => console.log(err));
};
更改我的代码后
action.js
import { postRequest } from '../services';
export const login = (email, password) => dispatch => {
postRequest('users/signin/', {
email: email,
password: password,
})
.then(res => {
dispatch({
type: LOGIN_USER,
payload: res.data,
});
})
.catch(err => console.log(err));
};
services.js
export const API_URL = 'localhost:8000/v1/';
export const postRequest = (request, body) => {
return axios.post(API_URL + request, body);
};
【问题讨论】: