如果 workbox-background-sync 表中有待处理的请求,我想在 Vue 中显示通知。这是我存储所有待处理请求的 IndexedDB。
这是我的 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');