当前位置:网站首页>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();
边栏推荐
- POJ - 3616 Milking Time(DP+LIS)
- Basic data types and string types are converted to each other
- Data type - floating point (C language)
- Through the "last mile" of legal services for the masses, fangzheng Puhua labor and personnel law self-service consulting service platform has been frequently "praised"
- Wang Zijian: is the NFT of Tencent magic core worth buying?
- 基本数据类型和string类型互相转化
- 如何在HarmonyOS应用中集成App Linking服务
- 使用SwinUnet训练自己的数据集
- JEditableTable的使用技巧
- rsync远程同步
猜你喜欢
AVL平衡二叉搜索树
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Data type - floating point (C language)
Pvtv2--pyramid vision transformer V2 learning notes
Deit learning notes
Splunk中single value视图使用将数值替换为文字
opencv学习笔记三——图像平滑/去噪处理
Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
使用SwinUnet训练自己的数据集
Iptables' state module (FTP service exercise)
随机推荐
Basic data types and string types are converted to each other
[IELTS speaking] Anna's oral learning records part2
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
Ebpf cilium practice (1) - team based network isolation
Data type - integer (C language)
It's too true. There's a reason why I haven't been rich
POJ - 3784 Running Median(对顶堆)
Interface as a parameter (interface callback)
GFS分布式文件系统
如何在HarmonyOS应用中集成App Linking服务
Practice of combining rook CEPH and rainbow, a cloud native storage solution
Train your dataset with swinunet
Give full play to the wide practicality of maker education space
PLSQL的安装和配置
Infix keyword infix expression and the use of generic extension function in kotlin
Obsidan之数学公式的输入
GOLand idea intellij 无法输入汉字
使用BiSeNet实现自己的数据集
Bisenet features
Go语言中,函数是一种类型