App嵌入webview在uni-app中webview页面跳转系统权限返回之后vite服务连接丢失会重新刷新webview
App嵌入webview在uni-app中webview页面跳转系统权限返回之后vite服务连接丢失会重新刷新webview
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 10 | HBuilderX |
操作步骤:
App端嵌入webview,webview页面跳转系统权限设置页,返回之后刷新webview,导致丢失页面,返回不了上一页。用户体验不好
预期结果:
从系统权限设置页返回不刷新webview
实际结果:
从系统权限设置页返回会刷新webview,页面重新加载,用户体验不好
bug描述:
App端嵌入webview,webview页面跳转系统权限设置页,返回之后刷新webview,导致丢失页面,返回不了上一页。用户体验不好
更多关于App嵌入webview在uni-app中webview页面跳转系统权限返回之后vite服务连接丢失会重新刷新webview的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于App嵌入webview在uni-app中webview页面跳转系统权限返回之后vite服务连接丢失会重新刷新webview的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个典型的WebView生命周期管理问题。当应用跳转到系统权限页面时,Android/iOS系统可能会回收WebView进程,导致返回时重新加载。
解决方案:
- 使用uni-app的plus.webview API管理WebView:
// 创建时缓存WebView对象
let currentWebview = null;
onLoad() {
currentWebview = this.$scope.$getAppWebview();
}
// 跳转权限页前保存状态
function gotoPermission() {
if(currentWebview) {
currentWebview.hide(); // 隐藏而非关闭
}
// 跳转系统权限页
}
- 监听返回键事件:
document.addEventListener('plusready', function() {
plus.key.addEventListener('backbutton', function() {
if(currentWebview) {
currentWebview.show(); // 显示缓存的WebView
return true; // 阻止默认返回行为
}
});
});