0

我可以让同步工作并清除 IndexedDB 队列,但数据没有存储在我的 mysql 数据库中。有什么我想念的吗?

我的服务人员:

importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.1.1/workbox-sw.js');

// This is the "Offline copy of assets" service worker

const CACHE = "pwabuilder-offline";
const SYNC = "bgSync"
const QUEUE_NAME = "bgSyncQueue";


self.addEventListener("message", (event) => {
  if (event.data && event.data.type === "SKIP_WAITING") {
    self.skipWaiting();
  }
});

workbox.routing.registerRoute(
    new RegExp('/*'),
    new workbox.strategies.NetworkFirst({
      cacheName: CACHE
    })
);

const bgSyncPlugin = new workbox.backgroundSync.BackgroundSyncPlugin(QUEUE_NAME, {
    maxRetentionTime: 24 * 60 // Retry for max of 24 Hours (specified in minutes)
  });

workbox.routing.registerRoute(
  new RegExp('^https:\/\/domain.com\/[a-zA-Z]+\/journal'),
  new workbox.strategies.NetworkOnly({
    plugins: [bgSyncPlugin]
  }),
  'POST'
);
4

1 回答 1

0

好吧,原来后台同步不喜欢在浏览器中进行测试。通过已安装的应用程序在我的手机上尝试过,效果很好。

于 2021-04-06T13:55:46.837 回答