ton*_*on1 5 react-native redux redux-thunk axios
我使用 设置我的本地服务器express.js,它只是处理请求并返回简单的消息。
app.get('/hello', (req, res) => {
res.send('Hello world !');
});
Run Code Online (Sandbox Code Playgroud)
我执行了服务器并在网络浏览器上对其进行了测试,效果很好。
只是我想在我的 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);
});
};
};
Run Code Online (Sandbox Code Playgroud)
它只返回catch()结果。
可能未处理的承诺拒绝(id:0):网络错误错误:createError时的网络错误......
也许出了什么问题,但我找不到它是什么。
我怎样才能解决这个问题?
ton*_*on1 15
解决了。
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
| 归档时间: |
|
| 查看次数: |
19393 次 |
| 最近记录: |