Blame view

Yi.Vben5.Vue3/docs/src/en/guide/in-depth/check-updates.md 1.52 KB
515fceeb   “wangming”   框架初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  # Check Updates
  
  ## Introduction
  
  When there are updates to the website, you might need to check for updates. The framework provides this functionality. By periodically checking for updates, you can configure the `checkUpdatesInterval` and `enableCheckUpdates` fields in your application's preferences.ts file to enable and set the interval for checking updates (in minutes).
  
  ```ts
  import { defineOverridesPreferences } from '@vben/preferences';
  
  export const overridesPreferences = defineOverridesPreferences({
    // overrides
    app: {
      // Whether to enable check for updates
      enableCheckUpdates: true,
      // The interval for checking updates, in minutes
      checkUpdatesInterval: 1,
    },
  });
  ```
  
  ## Effect
  
  When an update is detected, a prompt will pop up asking the user whether to refresh the page:
  
  ![check-updates](/guide/update-notice.png)
  
  ## Replacing with Other Update Checking Methods
  
  If you need to check for updates in other ways, such as through an API to more flexibly control the update logic (such as force refresh, display update content, etc.), you can do so by modifying the `src/widgets/check-updates/check-updates.vue` file under `@vben/layouts`.
  
  ```ts
  // Replace this with your update checking logic
  async function getVersionTag() {
    try {
      const response = await fetch('/', {
        cache: 'no-cache',
        method: 'HEAD',
      });
  
      return (
        response.headers.get('etag') || response.headers.get('last-modified')
      );
    } catch {
      console.error('Failed to fetch version tag');
      return null;
    }
  }
  ```