当前位置:网站首页>uniapp-监听app是否有网络连接
uniapp-监听app是否有网络连接
2022-07-28 05:18:00 【SheepOnTheCloud】
经过多次试验与查阅相关资料证实uniapp官网提供的
uni.getNetworkType({ success: function (res) { console.log(res.networkType); } })
方法是无法实现监听的,官网所说的监听是指网络变化的时候被调用,实现监听要配合两个api使用
网络变化触发回调函数
uni.onNetworkStatusChange(function(res) {
let title = `您当前处于${res.networkType}网络,请您注意隐私安全`
if(res.networkType=='none')title ='当前无网络连接'
uni.showToast({
title,
icon: 'none'
});
});获取初始的网络状态
uni.getNetworkType({
success: function (res) {
console.log(res.networkType);//网络类型 wifi、2g、3g、4g、ethernet、unknown、none
if(res.networkType === "none"){
console.log("当前无网络");
}else{
console.log("有网络");
}
}
});总结
app网络监控要先获取网络状态,再配置网络变化回调api
边栏推荐
猜你喜欢

链表实现增删查改

树莓派串口配置

Writing methods of scientific research papers: add analysis and discussion in the method part to explain their contributions and differences

科研论文写作方法:在方法部分添加分析和讨论说明自己的贡献和不同

visio如何精确控制图形的大小和位置及角度

Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid

Idea uses dev tool to realize hot deployment

Mutual conversion between latex and word

c语言:通过一个例子来认识函数栈帧的创建和销毁讲解

A file upload tool website written by individuals
随机推荐
链表中关于快慢指针的oj题
ByteBuffer. Position throws exception illegalargumentexception
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
GET与POST区别
Fusiongan code learning (I)
Oracle view lock table statement and unlocking method
冶金物理化学复习 --- 液 - 液相反应动力学
Pytorch uses maxpool to realize image expansion and corrosion
五子棋优化版
集合框架的操作使用
c语言:通过一个例子来认识函数栈帧的创建和销毁讲解
openjudge:校园食宿预订系统
Operation and use of collection framework
Openjudge: judge whether the string is palindrome
BeanUtils. Copyproperties cannot copy different list sets problem solving lists.transform function
Solve the problem that Oracle cannot use more than 1000 in statements
visio如何快速生成相同的图案,生成图像矩阵
URL 形式
使用深度学习训练图像时,图像太大进行切块训练预测
链表实现增删查改