zoukankan      html  css  js  c++  java
  • Vue HTML5+ APP热更新

    <script>
    export default {
      data() {
        return {
          version: "2.0.5",
        };
      },
      methods: {
        // 下载wgt文件
        downWgt(wgtUrl) {
          const that = this;
          plus.nativeUI.showWaiting("发现新版本,正在下载更新文件,请稍后...");
          plus.downloader
            .createDownload(
              wgtUrl,
              {
                filename: "_doc/update/",
              },
              function (d, status) {
                if (status == 200) {
                  console.log("下载更新文件成功:" + d.filename);
                  that.installWgt(d.filename); //安装wgt包
                } else {
                  console.log("下载失败!");
                  plus.nativeUI.alert("下载失败!");
                  plus.nativeUI.alert(JSON.stringify(d));
                  plus.nativeUI.alert(status);
                }
                plus.nativeUI.closeWaiting();
              }
            )
            .start();
        },
        installWgt(path) {
          plus.nativeUI.showWaiting("正在安装更新文件...");
          plus.runtime.install(
            path,
            {},
            function () {
              plus.nativeUI.closeWaiting();
              console.log("安装更新文件成功!");
              plus.nativeUI.alert("应用资源更新完成!", function () {
                plus.runtime.restart();
              });
            },
            function (e) {
              plus.nativeUI.closeWaiting();
              console.log("安装更新文件失败[" + e.code + "]:" + e.message);
              plus.nativeUI.alert("安装更新文件失败[" + e.code + "]:" + e.message);
              if (e.code == 10) {
                alert("请清除临时目录");
              }
            }
          );
        },
        plusReady() {
          const that = this;
          // plus.nativeUI.alert(plus.runtime.version);
          this.post("login/app_update", {
            version: this.version,
          }).then((res) => {
            const resData = res.data;
            if (resData.data.update === 1) {
              this.downWgt(resData.data.upgradeUrl);
            }
          });
        },
    
      },
      mounted() {
        this.post("login/app_update", {
          version: this.version,
        }).then((res) => {});
        if (window.plus) {
          this.plusReady();
        } else {
          document.addEventListener("plusready", this.plusReady, false);
        }
      },
    };
    </script>
    

    更多内容参考uni-app 整包升级/更新方案

  • 相关阅读:
    2020面试有感(1)
    多线程与异步
    GP-荧光免疫分析仪SDK 协议
    FastReport模板设计和调用
    EF的多线程与分库架构设计实现(2)
    HTML页面转化为带有水印的PDF文件
    利用 html2canvas+jsPDF 把 HTML元素 转化为PDF文件,以及遇到的坑
    前端json数据格式化显示
    单元测试——引入Vuex
    单元测试——引入vue-router和APP.vue文件
  • 原文地址:https://www.cnblogs.com/aahan/p/14134059.html
Copyright © 2011-2022 走看看