1、 重载页面、
onload {uni.onNetworkStatusChange(this.onNetworkStatusChange);}method: {onNetworkStatusChange(res) {if (res.isConnected) { // 当网络连接后的逻辑 uni.showToast({ title: "网络已连接" }); // 刷新页面 // uni.reLaunch({ // url: "/" + this.$options.name // }); // 重启应用} else { // 当网络断开后的逻辑 uni.showToast({ title: "网络已断开" }); } },}
重启应用
如果逻辑复杂建议重启应用
if (plus.os.name.toLowerCase() === 'ios') {plus.runtime.restart(function() {console.log("应用已重启");}, function(error) {console.error("重启应用失败: " + error.message);});
} else {console.log("该功能仅支持iOS平台");
}