checkNetwork() {
var flag = true;
wx.getNetworkType({
success(res) {
const networkType = res.networkType
if ("none" == networkType) {
flag = false;
wx.showToast({
title: '请连接网络',
duration: 800,
mask: true,
icon: 'error'
})
} else {
console.log("已经联网," + new Date())
flag = true
}
},
fail(err) {
console.log(err)
},
complete(cpe) {
console.log(cpe)
return flag;
}
})
},
onRefresh() {
console.log('onRefresh...')
var flag = this.checkNetwork();
if (!flag) {
return
}
....开始查询......
}
--------
【JobShow互联网大厂-裁员加班薪资-实况,求职避坑指南。薪火相传,欢迎新增,欢迎转发👏👏👏】
【发布3天:累计访问人数 5000+】
Promise
了解一下
稍微改动了一下。 checkNetwork() { return new Promise((resolve, reject) => { var flag = true; wx.getNetworkType({ success(res) { const networkType = res.networkType if ("none" == networkType) { flag = false; wx.showToast({ title: '请连接网络', duration: 800, mask: true, icon: 'error' }) } else { console.log("已经联网," + new Date()) flag = true } }, fail(err) { console.log(err) }, complete(cpe) { console.log(cpe) //return flag; resolve(flag) } }) //getNetworkType }) }, onRefresh() { console.log('onRefresh...') this.checkNetwork() .then((flag) => { if (!flag) { return } ....开始查询...... }) }