如果workbox-background-sync表中有待处理的请求,我想在Vue中显示通知。 This is my IndexedDB where I store all pending requests.
这是我的service-worker.js文件
const showNotification = () => {
self.registration.showNotification('Sync success!', {
body: 'Queue Resolved '?'',
});
};
const bgSyncPlugin = new workbox.backgroundSync.Plugin('offlineData', {
maxRetentionTime: 24 * 60, // Retry for max of 24 Hours (specified in minutes)
callbacks: {
queueDidReplay: showNotification,
},
});
const networkWithBackgroundSync = new workbox.strategies.NetworkOnly({
plugins: [bgSyncPlugin],
});
workbox.routing.registerRoute(/\/*/, networkWithBackgroundSync, 'POST');