我正在尝试显示保存到后端文件夹的上传图像。它位于不同的文件中,因此要检索我必须将其称为 http://localhost:3333/userprofile/5/5.jpeg 。但它不适用于我的 React Native 代码,我在 Android 和 IOS 上都测试了它
<Thumbnail
small
source={{
uri: `http://localhost:3333/userprofile/${this.props.user.id}/${this.props.user.avatar}`
}}
/>
当我在浏览器上打开它时它就起作用了。如果我使用不同的网址(如 https://picsum.photos/200/300),它也可以工作。怎么处理这个问题?
最佳答案
如果您使用的是 Android 模拟器,则必须使用 10.0.2.2
来访问 PC 上的本地主机。如果您使用的是真实设备,那么您需要位于同一个 wifi 网络上,并且必须使用 PC 的 IP,而不是 localhost
关于javascript - react native : Serving URI from localhost not rendering the image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58024881/