我正在使用Image组件来显示来自网络的图像。
问题:
如果网络上不存在图片,我想使用默认设置 图片。有一个defaultImage选项但在android上不受支持。
android和ios都有解决方案吗?
我想避免向其发送另一个HTTP / HTTPS请求 测试404。
答案 0 :(得分:2)
标签上有一个onError prop,可用于处理' 404'
例如使用状态:
<Image
source={this.state.thumbnail}
onError={(e) => {
console.log(e.nativeEvent.error);
this.setState({thumbnail: thumbnailDefaultImage});
}
}
/>
请点击此处查看不同的道具:http://facebook.github.io/react-native/docs/image.html#onError