Home  >  Article  >  Web Front-end  >  What should I do if uniapp has no network?

What should I do if uniapp has no network?

coldplay.xixi
coldplay.xixiOriginal
2020-12-16 15:09:416502browse

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 ()].

What should I do if uniapp has no network?

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

What should I do if uniapp has no network?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn