如何修复此 axios 调用

how to fix this axios call

我更改了我的代码以在一个地方处理 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);
};

你是否忘记了 API_URL 上的 'http:'?

导出常量API_URL = 'http://localhost:8000/v1/';