uniapp 更新apk有缓存点不动,卸载安装apk没有问题。android

方式一。

pages.json:

javascript 复制代码
"globalStyle" : {
        "navigationBarTextStyle" : "black",
        "navigationBarTitleText" : "uni-app",
        "navigationBarBackgroundColor" : "#F8F8F8",
        "backgroundColor" : "#F8F8F8",
        "app-plus" : {
            "titleNView" : false,
			"softinputMode": "adjustResize"
        },
		"disableScroll": true // 禁用旧版页面缓存
    },

方式二。

App.vueonLaunch 中添加:

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);
  }
}