sen
1 天以前 7ed2a032d0724e68aec8af940f2ce0023a9f0eb7
ui/car_wx_app/App.vue
@@ -1,7 +1,11 @@
<script>
  export default {
      onLaunch: function() {
          // #ifdef MP-WEIXIN
             this.updateApp()
             // #endif
         console.log('App Launch')
      },
      onShow: function() {
@@ -10,6 +14,46 @@
      },
      onHide: function() {
         console.log('App Hide')
      },
      methods:{
         updateApp() {
            const updateManager = uni.getUpdateManager();
            updateManager.onCheckForUpdate(function (res) {
               // 请求完新版本信息的回调
               console.log('检查更新结果:', res.hasUpdate);
               if (res.hasUpdate) {
                  console.log('发现新版本,正在下载...');
               } else {
                  console.log('当前已是最新版本');
               }
            });
            updateManager.onUpdateReady(function (res) {
               uni.showModal({
                  title: '更新提示',
                  content: '新版本已经准备好,是否重启应用?',
                  success(res) {
                     if (res.confirm) {
                        // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                        updateManager.applyUpdate();
                     }
                  }
               });
            });
            updateManager.onUpdateFailed(function (res) {
               // 新的版本下载失败
               uni.showModal({
                  title: '更新失败',
                  content: '新版本下载失败,请检查网络后重试',
                  showCancel: false
               });
            });
         }
      }
   }
</script>