【问题标题】:Possible Unhandled Promise Rejection Network Error in React NativeReact Native 中可能出现未处理的 Promise Rejection 网络错误
【发布时间】:2017-07-25 02:13:11
【问题描述】:

我使用express.js 设置我的本地服务器,它只是处理请求并返回简单的消息。

app.get('/hello', (req, res) => {
    res.send('Hello world !');
});

我执行了服务器并在网络浏览器上对其进行了测试,它运行良好。

我只是想在我的 react-native 应用上这样做。

这是我的action.js 文件

import axios from 'axios';

exports.helloButtonPressAct = (email, password) => {
    return function (dispatch) {
        return axios.get('http://localhost:3000/hello')
            .then(function (response) {
                console.log(response);

                // and create action obj here
                // dispatch(someAction(...))
            })
            .catch(function (error) {
                throw error;
                console.log(error);
            });
    };
};

它只返回catch() 结果。

可能的未处理承诺拒绝(id:0):网络错误错误: createError 处的网络错误 ...

可能有问题,但我找不到问题所在。

我该如何解决这个问题?

【问题讨论】:

    标签: react-native redux axios redux-thunk


    【解决方案1】:

    解决了。

    return axios.get('http://localhost:3000/hello')

    return axios.get('http://10.0.0.2:3000/hello')

    它有效。

    在 Android 模拟器中,localhost 指的是它的设备。

    https://github.com/facebook/react-native/issues/10404

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-12
      • 2017-01-25
      • 2022-08-04
      • 2019-12-22
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2018-08-06
      相关资源
      最近更新 更多