react-native - 有什么方法可以学习 uri 没有图像 react-native
问题描述
我正在开发一个电子商务应用程序,有些产品没有图片,因此有时 ıimage 组件看起来是空的。看起来很糟糕。(要获取图片,我正在使用 uri。)
我的问题是我怎么知道那个uri上没有图片?
<FastImage
source={{
uri: photoUri,
priority: FastImage.priority.high,
}}
style={styles.logo}
/>
解决方案
你可以试试 react-native-elements,它会在 uri 错误时显示 PlaceholderImage
import { Image as ImageElement } from 'react-native-elements'
import { Image } from 'react-native'
<ImageElement
style={{ width: 100, height: 100 }}
source={{ uri: reduceImageSize(item.image, width) }}
PlaceholderContent={(
<Image source={require('image-placeholder.png')} style={{ width: 100, height: 100 }} />
)}
/>
推荐阅读
- java - 查看 int 数组并忽略数字的倍数的方法
- ios - 在哪里存储我的 MusicKit 应用程序的开发者令牌?
- java - 仅过滤掉与某个元素匹配的列表的第一个元素的替代方法
- spring-boot - Swagger ui在zuul后面的时候在测试页面增加了一个/path
- angular - 模板解析错误:无法绑定到“formGroup”,因为它不是“form”的已知属性
- angular - Angular 应用程序的业务规则引擎
- css - CSS3不确定的进度条不会冻结
- python - 在 TensorFlow 中实施 CIFAR10 时遇到问题
- c# - 如何始终调用 C# 类的最新字段
- ruby-on-rails - 将 form_for 语法转换为 simple_form 语法