当前位置:网站首页>Uniapp monitor whether the app has a network connection
Uniapp monitor whether the app has a network connection
2022-07-28 07:04:00 【SheepOnTheCloud】
It has been proved by many tests and consulting relevant data uniapp Provided by the official website
uni.getNetworkType({ success: function (res) { console.log(res.networkType); } })
Method cannot realize monitoring , The monitoring mentioned on the official website refers to being called when the network changes , To realize monitoring, we need to cooperate with two api Use
Network change triggers callback function
uni.onNetworkStatusChange(function(res) {
let title = ` You are currently in ${res.networkType} The Internet , Please pay attention to privacy `
if(res.networkType=='none')title =' There is currently no network connection '
uni.showToast({
title,
icon: 'none'
});
});Get the initial network status
uni.getNetworkType({
success: function (res) {
console.log(res.networkType);// Network type wifi、2g、3g、4g、ethernet、unknown、none
if(res.networkType === "none"){
console.log(" There is no network at present ");
}else{
console.log(" There's a network ");
}
}
});summary
app Network monitoring needs to get the network status first , Reconfigure network change callback api
边栏推荐
- PXE unattended installation management
- SSH service configuration
- Servlet
- Archery database audit platform deployment
- Small turtle C (Chapter 6 arrays 1 and 2)
- Result number of filled briquettes
- Principle and configuration of NAT and pat
- Ubuntu MySQL setting remote access permissions
- [learning notes] thread creation
- Result fill in the blank (dfs*c language)
猜你喜欢

三层交换和VRRP

DHCP principle and configuration

Technology sharing | how to simulate real use scenarios? Mock technology to help you

Custom component -- data listener

MOOC Weng Kai C language week 3: judgment and circulation: 2. circulation

shell脚本——正则表达式

Monotonic queue, Luogu p1886 sliding window

SSH service configuration

Technology sharing | common proxy tools for interface testing

VLAN的配置
随机推荐
LNMP搭建过程详解
Animation animation realizes the crossing (click) pause
Test life | second tier cities with an annual salary of more than 40W? How did you achieve 100% salary increase under the epidemic?
Installation and configuration of unit test framework jest with typescript
Wechat applet custom compilation mode
MOOC Weng Kai C language week 7: array operation: 1. array operation 2. Search 3. preliminary sorting
Applet navigator cannot jump (debug)
Technology sharing | send requests using postman
MySQL build database Series (I) -- download MySQL
MOOC翁恺C语言 第四周:进一步的判断与循环:3.多路分支4.循环的例子5.判断和循环常见的错误
shell脚本——“三剑客”之awk命令
Asynchronous programming promise
Ubuntu MySQL setting remote access permissions
Servlet
MySQL installation and use
Ubuntu18.04 set up redis cluster [learning notes]
NFS 共享存储服务
Network - data link layer
Custom components -- styles
Vmware workstation configuration net mode