reactjs - 即使图像路径正确,React-Native -Elements Avatar 也不会渲染并仅显示灰色背景
问题描述
我正在尝试在我的 React_Native 应用程序的 listItem 中呈现头像,但即使我的图像 URI 路径正确并且它只给出灰色背景,图像也没有呈现。
这是我的代码
<View>
{props.dishes.map((l, i) => (
<ListItem key={i} bottomDivider>
<Avatar rounded source={{ uri: l.image }} />
<ListItem.Content>
<ListItem.Title>{l.name}</ListItem.Title>
<ListItem.Subtitle>{l.description}</ListItem.Subtitle>
</ListItem.Content>
</ListItem>
))}
</View>
这是我得到的图像
我希望在那里渲染图像,但它只显示灰色背景。我还尝试放置在线图像的 URI,但它给出了相同的结果。
我也遵循了这里提到的解决方案,但它不起作用。
我还通过了在线 uri 来检查我的路径 uri 是否不正确,但结果相同
<Avatar
source={{
uri:"https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg",
}}
/>
解决方案
我解决了这个问题,因为像这样传递图像的路径不起作用绕过像这样的图像路径只呈现灰色背景。
<Avatar rounded source={{ uri: "./images/uthappizza.png"}} />
这就是我使用 require() 正确传递图像路径及其渲染的方式
<Avatar rounded source={require("./images/uthappizza.png")} />
推荐阅读
- sharepoint - ConvertTo-PnPPage:找不到文件“PnP.Framework.resources”
- php - Laravel 不保存布尔值到数据库
- reactjs - Simple-Peer:接听电话后其他视频无法呈现
- reactjs - 反应useState不输出
- java - 输出不断重复,输入Y或N后不循环也不结束程序 - Java
- python - 如何修复此属性错误python?
- c++ - sizeof (FTransform) 小于 sizeof(FMatrix),为什么以及如何?ELI5?
- javascript - 为什么 document.cookie 路径出现在 value 列中?
- python - 在 Python 上使用 Azure 函数的雪花外部函数不起作用
- kubernetes - 在 CentOS(calico)上启用防火墙的 Kubernetes 集群无法正常工作