当前位置:网站首页>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();
边栏推荐
- Input of mathematical formula of obsidan
- Greenplum6.x-版本变化记录-常用手册
- Greenplum6.x常用语句
- MySQL partition explanation and operation statement
- opencv 将16位图像数据转为8位、8转16
- Thirteen forms of lambda in kotlin
- Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
- Opencv learning note 4 - expansion / corrosion / open operation / close operation
- In go language, function is a type
- Mock. JS usage details
猜你喜欢

Routing information protocol rip

Rapid integration of authentication services - harmonyos platform

Opencv learning note 4 - expansion / corrosion / open operation / close operation

調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error

21 general principles of wiring in circuit board design_ Provided by Chengdu circuit board design

ncs成都新電面試經驗

联想混合云Lenovo xCloud:4大产品线+IT服务门户

Greenplum 6.x build_ install
![[Nanjing University] - [software analysis] course learning notes (I) -introduction](/img/57/bf652b36389d2bf95388d2eb4772a1.png)
[Nanjing University] - [software analysis] course learning notes (I) -introduction

Arm GIC (IV) GIC V3 register class analysis notes.
随机推荐
[Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene
Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
如何在图片的目标中添加目标的mask
2-3查找樹
About using CDN based on Kangle and EP panel
21 general principles of wiring in circuit board design_ Provided by Chengdu circuit board design
Required String parameter ‘XXX‘ is not present
下载和安装orcale database11.2.0.4
[hard core science popularization] working principle of dynamic loop monitoring system
登山小分队(dfs)
leetcode135. Distribute candy
Count sort (diagram)
Three usage scenarios of annotation @configurationproperties
AVL平衡二叉搜索树
How to add a mask of a target in a picture
2-3 lookup tree
Greenplum 6.x build_ install
POJ - 3616 Milking Time(DP+LIS)
Three series of BOM elements
路由信息协议——RIP