当前位置:网站首页>uniapp 微信小程序监测网络
uniapp 微信小程序监测网络
2022-07-07 05:45:00 【杜蜜月】
/** * 判断是否有网络 */
export default function useNetWork() {
getNetStatus().then(res => {
console.log('有网', res);
}).catch(res => {
setTimeout(() => {
uni.showToast({
title: '请检查您的网络连接',
icon: 'none',
duration: 3000,
})
}, 100)
wx.onNetworkStatusChange(function(res) {
if (res.isConnected) {
uni.showToast({
title: '网络已恢复',
icon: 'none',
duration: 1000,
})
} else {
useNetWork();
}
})
})
}
function getNetStatus(){
return new Promise((resolve, reject) => {
wx.getNetworkType({
success (res) {
const networkType = res.networkType;
if (res.networkType === 'none') {
reject();
} else {
resolve();
}
}
})
})
}
使用:
//在请求接口之前调用这个方法即可
useNetWork();
边栏推荐
- Use of out covariance and in inversion in kotlin
- [Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
- POJ - 3784 running medium
- Go语言中,函数是一种类型
- 2-3查找樹
- Data type - integer (C language)
- The use of generics and vararg variable parameters in kotlin
- GOLand idea intellij 无法输入汉字
- [quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)
- Deit learning notes
猜你喜欢

opencv学习笔记四——膨胀/腐蚀/开运算/闭运算

What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking

Opencv learning note 3 - image smoothing / denoising

Splunk中single value视图使用将数值替换为文字

23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP

AVL balanced binary search tree

Iptables' state module (FTP service exercise)

Input of mathematical formula of obsidan
![[hard core science popularization] working principle of dynamic loop monitoring system](/img/d4/0c0281aec5a4f444528e8cfd401598.jpg)
[hard core science popularization] working principle of dynamic loop monitoring system

2-3查找樹
随机推荐
Learn how to compile basic components of rainbow from the source code
Grpc, oauth2, OpenSSL, two-way authentication, one-way authentication and other column directories
Snyk 依赖性安全漏洞扫描工具
iptables 之 state模块(ftp服务练习)
The use of generics and vararg variable parameters in kotlin
Explore creativity in steam art design
Famine cloud service management script
Several ways of lambda used in functions in kotlin (higher-order functions)
Give full play to the wide practicality of maker education space
Splunk query CSV lookup table data dynamic query
接口作为参数(接口回调)
数据中台落地实施之法
MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
How to understand distributed architecture and micro service architecture
Domain specific language / DSL in kotlin
The truth of robot education in hands-on practice
[go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
SSM integration
基本数据类型和string类型互相转化
MES系統,是企業生產的必要選擇