代码:
onLaunch方法中调用:
this.checknetwork()
methods属性中定义了一个名为checknetwork的方法:
checknetwork() {
uni.onNetworkStatusChange(function(res) {
if (res.isConnected) {
uni.reLaunch({
url: '/pages/index/index'
})
} else {
uni.showModal({
title: '系统提示',
content: '当前设备无网络或网络较差',
cancelText: '取消',
confirmText: '确定',
success: (res) => {
if (res.confirm) {
uni.reLaunch({
url: '/pages/index/index'
})
} else {
// #ifdef H5
uni.reLaunch({
url: '/pages/index/index'
})
// #endif
// #ifdef APP-PLUS
plus.runtime.quit()
// #endif
}
}
})
}
})
} ,