uniapp 更新apk有缓存点不动,卸载安装apk没有问题。android
方式一。
pages.json:
"globalStyle" : {"navigationBarTextStyle" : "black","navigationBarTitleText" : "uni-app","navigationBarBackgroundColor" : "#F8F8F8","backgroundColor" : "#F8F8F8","app-plus" : {"titleNView" : false,"softinputMode": "adjustResize"},"disableScroll": true // 禁用旧版页面缓存},
方式二。
在 App.vue
的 onLaunch
中添加:
onLaunch() {// 版本变更检测const currentVersion = plus.runtime.version;const lastVersion = uni.getStorageSync('app_version');if (!lastVersion || lastVersion !== currentVersion) {// 关键操作:清除WebView缓存const webview = plus.webview.currentWebview();if (webview) {webview.clear(); // 清除当前WebView缓存}// 清除应用缓存plus.cache.clear();// 强制重启(关键!)setTimeout(() => {plus.runtime.restart();}, 500);// 存储新版本uni.setStorageSync('app_version', currentVersion);}
}