【发布时间】:2021-04-30 21:31:54
【问题描述】:
API 导入:
import axios from 'axios';
const Api = axios.create({ baseURL: 'exp://IP:19000' });
export default Api;
我使用它的组件:
const handlePress = async () => {
try {
await TaskService.create({ title: title })
} catch (error) {
console.error(error)
}
}
我之前收到过警告,但在使用 trycatch 后,我开始收到此错误: 网络错误
堆栈跟踪: node_modules/axios/lib/core/createError.js:16:14 in createError node_modules/axios/lib/adapters/xhr.js:84:24 in handleError 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 __didCompleteResponse 中的 node_modules/react-native/Libraries/Network/XMLHttpRequest.js:395:6 node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:189:10 在发出 __callFunction 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 __guard$argument_0 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 __guard 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue [本机代码]:callFunctionReturnFlushedQueue中的null
【问题讨论】:
标签: react-native axios