当前位置:网站首页>Uniapp wechat applet monitoring network
Uniapp wechat applet monitoring network
2022-07-07 08:48:00 【Du honeymoon】
/** * Judge whether there is a network */
export default function useNetWork() {
getNetStatus().then(res => {
console.log(' Have a net ', res);
}).catch(res => {
setTimeout(() => {
uni.showToast({
title: ' Please check your network connection ',
icon: 'none',
duration: 3000,
})
}, 100)
wx.onNetworkStatusChange(function(res) {
if (res.isConnected) {
uni.showToast({
title: ' The network has been restored ',
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();
}
}
})
})
}
Use :
// Call this method before requesting the interface
useNetWork();
边栏推荐
- How to understand distributed architecture and micro service architecture
- 为什么要选择云原生数据库
- xray的简单使用
- Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
- IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
- 数据分析方法论与前人经验总结2【笔记干货】
- Opencv learning note 3 - image smoothing / denoising
- Leetcode 1984. Minimum difference in student scores
- [Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
- Greenplum6.x常用语句
猜你喜欢
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
Opencv learning notes II - basic image operations
leetcode135. Distribute candy
国标GB28181协议视频平台EasyGBS新增拉流超时配置
ncs成都新电面试经验
关于基于kangle和EP面板使用CDN
随机推荐
FPGA knowledge accumulation [6]
[kuangbin] topic 15 digit DP
数据库存储---表分区
更改当前文件夹及文件夹下文件日期shell脚本
【踩坑】nacos注册一直连接localhost:8848,no available server
MySQL partition explanation and operation statement
Frequently Asked Coding Problems
Thirteen forms of lambda in kotlin
POJ - 3784 running medium
Qt Charts使用(重写QChartView,实现一些自定义功能)
redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“
POJ - 3784 Running Median(对顶堆)
快速集成认证服务-HarmonyOS平台
xray的简单使用
[Nanjing University] - [software analysis] course learning notes (I) -introduction
Database storage - table partition
IP地址的类别
Mock. JS usage details
[machine learning] watermelon book data set_ data sharing
Input and output of floating point data (C language)