方式一。
pages.json:
javascript
"globalStyle" : {
"navigationBarTextStyle" : "black",
"navigationBarTitleText" : "uni-app",
"navigationBarBackgroundColor" : "#F8F8F8",
"backgroundColor" : "#F8F8F8",
"app-plus" : {
"titleNView" : false,
"softinputMode": "adjustResize"
},
"disableScroll": true // 禁用旧版页面缓存
},
方式二。
在 App.vue
的 onLaunch
中添加:
javascript
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);
}
}