# 更新管理器(Updater)

前端重新部署通知页面刷新(定时器轮询)。

# 基本使用

import { Updater } from "@itriton/saber";
const updater = new Updater({
  timer: 2000,
});
updater.on("no-update", () => {
  console.log("暂未更新");
});
updater.on("update", () => {
  console.log("更新通知");
});

# 配合 vue 使用

import { Updater } from "@itriton/saber";
export default {
  name: "App",
  data(){
    return {
      isNewVersion: false
    }
  },
  mounted() {
    if (process.env.NODE_ENV === "production") {
      const updater = new Updater({
        timer: 2000,
      });
      updater.on("no-update", () => {
        this.isNewVersion = false;
      });
      updater.on("update", () => {
        if (!this.isNewVersion) {
          this.isNewVersion = true;
          this.$notify({
            title: "发现新版本",
            duration: 0,
            showClose: false,
            position: "bottom-right",
            dangerouslyUseHTMLString: true,
            onClick: () => {
              location.reload(true);
            },
            message: `
            <div>
              <div>新版本已经准备好,是否立即更新应用?</div>
              <div style='display:flex; justify-content: end; cursor: pointer; width: 280px;color:blue'>立即更新</div>
            </div>`
          });
        }
      });
    }
  }

提示

获取的是首页的 script 标签的哈希值进行对比版本信息

上次更新: 12/22/2023, 12:12:55 PM