【问题标题】:undefined response from axios.post来自 axios.post 的未定义响应
【发布时间】:2020-04-08 18:31:10
【问题描述】:

当我尝试发出发布请求时,我收到网络错误,错误消息为“未定义”

设置如下:

    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}],
      });
    });
};

【问题讨论】:

  • 你得到什么回应? likeafter .then 你已经打印了yes,尝试打印响应
  • 它正在直接捕获
  • 你能告诉我们减速器吗?,认为你在有效载荷上错了
  • 你试过邮递员吗?
  • 我处理更新略有不同,但我仔细检查了 redux 端是否工作正常。

标签: api react-native react-redux axios


【解决方案1】:

试试这个,简单易读……

      axios
        .post(api_url + '/v1/login?', data, {
          'Content-Type': 'application/json',
        })
        .then(
          res => {
            alert('Response');
          },
          error => {
             alert('Error');
          },
        );
    }
  };

【讨论】:

    猜你喜欢
    • 2018-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    • 2019-08-03
    相关资源
    最近更新 更多