2

我正在将我的网站移植到 vuepress,但我似乎无法让服务人员运行。文档说我只需要将配置中的serviceWorker布尔值设置为true. 所以我这样做了,它为我生成了一个服务人员。但它不会注册。

经过一段时间挖掘缩小代码并设置一些断点后,我找到了注册服务工作者的行。

Go.router.onReady(function () {
    Qo.$mount("#app"),
        "https:" === window.location.protocol && Xo("/vuepress-blog/service-worker.js", {
            ready: function () {
                console.log("[vuepress:sw] Service worker is active."),
                    Qo.$refs.layout.$emit("sw-ready")
            },
            cached: function () {
                console.log("[vuepress:sw] Content has been cached for offline use."),
                    Qo.$refs.layout.$emit("sw-cached")
            },
            updated: function () {
                console.log("[vuepress:sw] Content updated."),
                    Qo.$refs.layout.$emit("sw-updated")
            },
            offline: function () {
                console.log("[vuepress:sw] No internet connection found. App is running in offline mode."),
                    Qo.$refs.layout.$emit("sw-offline")
            },
            error: function (t) {
                console.error("[vuepress:sw] Error during service worker registration:", t),
                    Qo.$refs.layout.$emit("sw-error", t)
            }
        })
})

它被混淆了,所以我不完全确定GoQo变量是什么,但它似乎试图在onReady触发路由器事件时注册一个服务工作者。但是,这个事件永远不会被触发。

这就是我卡住的地方。我完全不知道为什么这个函数不会被触发。

该项目的 repo 在 GitLab 上公开可用并部署在GitLab Pages上。我真的很感激这方面的一些帮助。

4

0 回答 0