javascript - react native : Serving URI from localhost not rendering the image

标签 javascript reactjs react-native

我正在尝试显示保存到后端文件夹的上传图像。它位于不同的文件中,因此要检索我必须将其称为 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/

相关文章:

javascript - 带有渲染的 Reactjs 意外无限循环

javascript - 从 Backbone.js 模型中删除属性

javascript - 复杂的 IF 语句问题

javascript - 修改更改击键文字的代码以在 contenteditable 而不是 textarea 中工作

javascript - React-intl 在 Safari v8.0.8 上禁用 react-router 的 Link 组件 onClick 事件

reactjs - 刷新 firebase id token 服务器端

javascript - React-Native 选择器警告

react-native - 在按下事件时响应 Native Touchable

javascript - react-native 链接找不到 project.pbxproj 文件

javascript - JavaScript 中的对象数组