错误[类型错误:网络请求失败]

问题描述 投票:0回答:2

我在用于 API 集成的 React Native expo app js 文件中收到错误 [TypeError: Network request failed]。在我的 React js Web 开发中使用相同的 API,效果很好。但它在我的 React Native Expo 移动应用程序中不起作用。

react-native api react-hooks expo react-native-flatlist
2个回答
0
投票

请勿使用我们的网络公共 IPv4 地址来使用本地主机地址。


0
投票

不要从您的应用程序引用

localhost
- 相反,在本地开发期间您可以直接指定 IP 地址。幸运的是,您可以使用
expo-constants
在运行时获得此信息。

import Constants from "expo-constants";

const { manifest } = Constants;

const uri = `http://${manifest.debuggerHost.split(':').shift()}:3000`;
© www.soinside.com 2019 - 2024. All rights reserved.