当前位置:网站首页>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();
边栏推荐
- MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
- Installation and configuration of PLSQL
- ES6_ Arrow function
- Laravel8 uses passport login and JWT (generate token)
- Virtual address space
- [hard core science popularization] working principle of dynamic loop monitoring system
- It's too true. There's a reason why I haven't been rich
- AVL balanced binary search tree
- 关于基于kangle和EP面板使用CDN
- One click installation of highly available Nacos clusters in rainbow
猜你喜欢
Ebpf cilium practice (2) - underlying network observability
GFS分布式文件系统
Merge sort and non comparison sort
Data type - floating point (C language)
SSM integration
SSM 整合
Splunk中single value视图使用将数值替换为文字
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
Ebpf cilium practice (1) - team based network isolation
Open3D ISS关键点
随机推荐
IELTS review progress and method use [daily revision]
Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
How to realize the high temperature alarm of the machine room in the moving ring monitoring system
单场带货涨粉10万,农村主播竟将男装卖爆单?
BiSeNet的特點
String operation
Golang 编译约束/条件编译 ( // +build <tags> )
Several ways of lambda used in functions in kotlin (higher-order functions)
Interface as a parameter (interface callback)
归并排序和非比较排序
Pytoch (VI) -- model tuning tricks
Ebpf cilium practice (1) - team based network isolation
opencv学习笔记二——图像基本操作
Arm GIC (IV) GIC V3 register class analysis notes.
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
DeiT学习笔记
Exercise arrangement 2.10, 11
POJ - 3616 Milking Time(DP+LIS)
In go language, function is a type