当前位置:网站首页>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();
边栏推荐
- MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
- [Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
- 指针进阶,字符串函数
- Mock.js用法详解
- Gson converts the entity class to JSON times declare multiple JSON fields named
- Other 7 features of TCP [sliding window mechanism ▲]
- How to understand distributed architecture and micro service architecture
- 登山小分队(dfs)
- 【MySQL】数据库进阶之触发器内容详解
- 字符串操作
猜你喜欢
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
Componentspace2022, assertions, protocols, bindings, and configuration files
[南京大学]-[软件分析]课程学习笔记(一)-introduction
Routing information protocol rip
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"
Teach you how to select PCB board by hand (II)
Opencv learning notes II - basic image operations
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
Opencv learning notes 1 -- several methods of reading images
如何在快应用中实现滑动操作组件
随机推荐
POJ - 3616 Milking Time(DP+LIS)
Redis summary
Go write a program that runs within a certain period of time
[wechat applet: cache operation]
NCS Chengdu Xindian interview experience
Opencv learning note 4 - expansion / corrosion / open operation / close operation
POJ - 3784 Running Median(对顶堆)
String operation
Database storage - table partition
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
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
oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
Greenplum6.x重新初始化
About using CDN based on Kangle and EP panel
数据分片介绍
2-3查找树
对API接口或H5接口做签名认证
求有符号数的原码、反码和补码【C语言】
QT charts use (rewrite qchartview to realize some custom functions)
2 - 3 arbre de recherche