React Native中Image报错Missing request token for request: <NSMutableURLRequest: 0x..>{URL:...png}

来源:互联网 发布:mac safari 强制刷新 编辑:程序博客网 时间:2024/06/11 15:18

首先贴出来报错:



这个问题,是因为用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;}




阅读全文
1 0
原创粉丝点击