首页 > 如何捕捉React Native Webview错误

如何捕捉React Native Webview错误

在使用webview,尝试过onError和renderError,但模拟器都是弹出红色错误页,无法显示自定义的错误视图,代码如下

<View style={styles.webview_body}>
   <WebView
      source={{uri:this.props.url}}
      onNavigationStateChange={this._onNavigationStateChange.bind(this)}
      renderError={(e)=>this.loadError.bind(this,e)}
      onError={(e)=>this.loadError.bind(this,e)}/>
</View>

  loadError(e){
    return(
  <View style={styles.errorview}>
    <Text>Error:{e}</Text>
  </View>
  )}

出错时(如访问一个不存在的URL,模拟器出现如下视图)

【热门文章】
【热门文章】