react-native - 当互联网连接不好时,在本机反应中显示错误
问题描述
我正在对我的 react native 应用程序进行最后修改。
好吧,我得到的问题是,当我输入我的信息进行连接时,我会在一个小框对话框中显示您的数据验证正在运行(这次是用于比较用户输入的信息和 sql server 数据)所以当它正确时,我正在访问主页。
我的问题是有时,互联网不是那么好,所以我需要当验证需要更长的时间来显示错误说“请验证您的互联网连接”
不知道有没有方法或者具体功能!!
constructor(props){
super(props);
this.state={
isModalVisible:false,
}}
openModal = () =>{
this.setState({
isModalVisible:true
}) }
userRegister = () =>{
this.openModal();
fetch('http://192.168.1.7:80/recup.php',{
method:'post',
header:{
'Accept':'application/json',
'Content-type' :'application/json'
},
body:JSON.stringify({email:usermail,password:password,})})
.then((responseData)=>responseData.text())
.then((responseJson)=>{
if(responseJson =='Data Matched'){
this.props.navigation.navigate( 'Welcome')}
else{
alert("Merci de saisir vos données correctement")}
})
.catch((error)=>{console.error(error);})
}
render() {
if(!this.state.isLoading){
return(
....
<TouchableOpacity style={styles.butt} onPress={this.userRegister}>
<Text>Connection</Text</TouchableOpacity>
....
解决方案
如果你想访问这个(我的意思是如果你想获取)url http://192.168.1.7:80/recup.php你应该有正确的互联网连接。您可以使用这个 react-native-netinfo 库来处理这个问题。https://github.com/react-native-community/react-native-netinfo
推荐阅读
- javascript - JavaScript 语法问题 - 返回“未定义”的函数
- javascript - ThreeJS:Water2 示例抛出“球体未定义”错误
- arguments - 在 LaTex 中制作参数图
- marie - Marisim 中的标签错误,关于如何修复它的任何建议?
- orocrm - OROCommerce 客户电子邮件模板样式
- android - 为什么我退出后重新进入我的应用程序时我的视频不播放?
- unit-testing - 如何在不持久化数据的情况下执行集成测试?
- bash - Unix将时间格式转换为整数值
- compiler-errors - 什么是在 DevOps 方面查看和解释日志文件
- r - 如何按日期对数据框进行排序。但日期列在季度