写在uniapp的APP.vue的onShow方法中

uni.onNetworkStatusChange(function(res) {
                if (res.isConnected) {
                    uni.showModal({
                        title: '系统提示',
                        content: '当前设备网络已恢复',
                        showCancel: false,
                        confirmText: '知道了'
                    })
                } else {
                    uni.showModal({
                        title: '系统提示',
                        content: '当前设备无网络或网络较差',
                        cancelText: '取消',
                        confirmText: '确定',
                        success: (res) => {
                            if (res.confirm) {
                                uni.reLaunch({
                                    url:'/pages/index/index'
                                })
                            } else {
                                // #ifdef H5
                                uni.navigateTo({
                                    url:'/pages/index/login'
                                })
                                // #endif
                                // #ifdef APP-PLUS
                                plus.runtime.quit()
                                // #endif
                            }
                        }
                    })
                }

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐