Home > Article > Web Front-end > What should I do if uniapp has no network?
Uniapp has no network solution: first determine whether the user is disconnected, the code is [this.isHaveNetwork()]; then find out the value of networkType and put it into the onshow page, the code is [this.isHaveNetwork ()].
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.
Recommended (free): uni-app development tutorial
Solution for uniapp without network:
When the user is in If the network is disconnected, we cannot request data. If there is loading, it will easily die.
So we determine whether the user is disconnected from the network when requesting
Define a method
isHaveNetwork(){ uni.getNetworkType({ success: (res) => { if(res.networkType=='none'){ uni.showModal({ title: '没有网络', content: '是否重新连接', success: (res) => { if (res.confirm) { this.isHaveNetwork() //再次判断 } else if (res.cancel) { } } }); }else{ this.getData('') //有网 } } }); },
The value of networkType
is placed on the onshow page
this.isHaveNetwork()
Related free learning recommendations: php programming(video)
The above is the detailed content of What should I do if uniapp has no network?. For more information, please follow other related articles on the PHP Chinese website!