VUE PWA离线事件未触发

时间:2020-01-21 17:27:06

标签: vue.js

我只是通过@ vue / cli中的pwa创建了一个新的vue应用程序。

当我切换到离线模式或以离线模式刷新页面时, 我确实希望看到以下消息:“未找到互联网连接。应用程序以脱机模式运行。”因为在registerServiceWorker.ts中有事件。

enter image description here

/* eslint-disable no-console */

import { register } from 'register-service-worker'

if (process.env.NODE_ENV === 'production') {
  register(`${process.env.BASE_URL}service-worker.js`, {
    ready () {
      console.log(
        'App is being served from cache by a service worker.\n' +
        'For more details'
      )
    },
    registered () {
      console.log('Service worker has been registered.')
    },
    cached () {
      console.log('Content has been cached for offline use.')
    },
    updatefound () {
      console.log('New content is downloading.')
    },
    updated () {
      console.log('New content is available; please refresh.')
    },
    offline () {
      console.log('No internet connection found. App is running in offline mode.')
    },
    error (error) {
      console.error('Error during service worker registration:', error)
    }
  })
}

0 个答案:

没有答案