【发布时间】:2019-10-30 12:52:08
【问题描述】:
我正在尝试向我的 nodeJS 后端 API 发出 axios 请求。 我正在使用 Genymotion,请求设置如下:
async componentDidMount() {
const response = await axios.get('http://10.0.3.2:3333/posts');
console.log(response)
}
所以我只遇到来自其他域的请求的问题
这是主要的入口点控制器:
Routes.js
routes.get('/posts', postController.index);
postController.index
async index(req, res) {
console.log(req)
const post = await Post.find().sort('-createdAt')
return res.json(post)
}
请求没有到达 console.log
【问题讨论】:
-
能否从后端添加返回数据的方法?
-
我已经编辑了问题
-
您确定您拨打了正确的电话
const response = await axios.get('http://10.0.3.2:3333/posts');?在您的浏览器中,您会看到http://localhost:3333/posts -
哦,您使用的是 Genymotion,只需确保主机正确,尝试在浏览器中访问
http://10.0.3.2:3333/posts可能吗? -
Genymotion 不使用本地主机进行连接
标签: node.js react-native asynchronous axios genymotion