File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,3 +46,47 @@ async function getVersionTag() {
4646 }
4747}
4848```
49+
50+ ## 替换为第三方库检查更新方式
51+
52+ 如果需要通过其他方式检查更新,例如使用其他版本控制方式(chunkHash、version.json)、使用` Web Worker ` 在后台轮询更新、自定义检查更新时机(不使用轮询),你可以通过JS库` version-polling ` 来实现。
53+
54+ ``` bash
55+ pnpm add version-polling
56+ ```
57+
58+ 以` apps/web-antd ` 项目为例,在项目入口文件` main.ts ` 或者` app.vue ` 添加以下代码
59+
60+ ``` ts
61+ import { h } from ' vue' ;
62+
63+ import { Button , notification } from ' ant-design-vue' ;
64+ import { createVersionPolling } from ' version-polling' ;
65+
66+ createVersionPolling ({
67+ silent: import .meta .env .MODE === ' development' , // 开发环境下不检测
68+ onUpdate : (self ) => {
69+ const key = ` open${Date .now ()} ` ;
70+ notification .info ({
71+ message: ' 提示' ,
72+ description: ' 检测到网页有更新, 是否刷新页面加载最新版本?' ,
73+ btn : () =>
74+ h (
75+ Button ,
76+ {
77+ type: ' primary' ,
78+ size: ' small' ,
79+ onClick : () => {
80+ notification .close (key );
81+ self .onRefresh ();
82+ },
83+ },
84+ { default : () => ' 刷新' },
85+ ),
86+ key ,
87+ duration: null ,
88+ placement: ' bottomRight' ,
89+ });
90+ },
91+ });
92+ ```
You can’t perform that action at this time.
0 commit comments