首先贴出来报错:
这个问题,是因为用Image组件请求网络图片的时候,每刷新十次会有一次没有请求到,偶然出现的报错。
解决这类问题,一定要对图片的URL地址进行判空:
源码供上:
{ Filter.isNotEmpty(this.props.upgradeObj) && Filter.isNotEmpty(this.props.upgradeObj.imgUrlPath) ?
<TouchableOpacity activeOpacity={1}
onPress={() => this.onPressBannerConfig(this.props.upgradeObj)}>
<Image source={{uri: this.props.upgradeObj.imgUrlPath}}
style={{width: deviceWidth * 0.76, height: deviceWidth * 0.84 ,resizeMode: Image.resizeMode.contain}}/>
</TouchableOpacity> : null
}
如何判断对象不为空:
/*判断对象为空*/
isEmpty(obj){
if(typeof (obj) != 'number' && (!obj || obj == null || obj == ' ' || obj == undefined || typeof (obj) == 'undefined')){
return true;
}
return false;
},
/*判断对象不为空*/
isNotEmpty(obj){
if(!this.isEmpty(obj)){
return true;
}
return false;
}