【发布时间】:2021-08-25 05:33:35
【问题描述】:
解决这个问题我太累了,我无法在 https 中工作,而且在 http 中无法解决,请帮助我
当我使用这个 api 时 => https://jsonplaceholder.typicode.com/posts 我没用,但是当我使用我的 api 时它就不起作用了
这是我的代码
import axios from 'axios'
let baseURL = ''
{
Platform.OS == 'android'
? baseURL = 'http://10.0.2.2:3000/api/v1/' // android
: baseURL = 'http://localhost:3000/api/v1/' // IOS
}
axios.get(`${baseURL}products`)
.then(res => {console.log(res) })
.catch(err => console.log(err)})
我有错误
网络错误 在 http://packager.x5-xy3.anonymous.g-bazar.exp.direct/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:189790:25 在 createError 在 node_modules\axios\lib\adapters\xhr.js:91:24 in handleTimeout 在 EventTarget.prototype.dispatchEvent 中的 node_modules\event-target-shim\dist\event-target-shim.js:818:20 在 setReadyState 中的 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 在 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 在 didCompleteResponse 在 node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 在发出 在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in callFunction 在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in guard$argument_0 在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 保护 在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 在 callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue
【问题讨论】:
标签: reactjs react-native api axios