来自uri的React Native图像未显示

时间:2021-06-28 11:56:03

标签: reactjs react-native

我正在开发一个移动应用程序,但是当我尝试从特定 uri 访问我的图像时,它不会显示它们。但它只在我朋友的电脑上显示,我也是这样做的。

enter image description here

在 3 个块内的文本上方应该有一个图像,但我收到一个错误。

代码:

<Image
   style={styles.image}
   source={{uri: 'http://10.0.2.2:8000/images/illustrations/' + illustration}}
   onError={(error) => console.error(error)}
/>

我不知道出了什么问题...

2 个答案:

答案 0 :(得分:0)

<块引用>

您必须在 react-native 中为图像提供宽度。如果路径正确,还要检查图像的路径,只需清除您的 Metro bundler 缓存并重新启动它。

<Image source={{ uri: 'http://10.0.2.2:8000/images/illustrations' + illustration }} style={{ height: 80, width: 80}} />

答案 1 :(得分:0)

也许尝试重新启动您的 Metro 捆绑包。

<Image source={{ uri: `http://10.0.2.2:8000/images/illustrations/${illustration}`}} style={{ height: 80, width: 80}}
相关问题