【问题标题】:Network Error while connecting Axios to React Native将 Axios 连接到 React Native 时出现网络错误
【发布时间】: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


    【解决方案1】:

    尝试使用 .then() .catch() 承诺

    【讨论】:

      猜你喜欢
      • 2022-09-30
      • 2020-03-09
      • 2020-04-23
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 2017-12-29
      • 2020-08-22
      相关资源
      最近更新 更多