Nuxt is based on Vue.js and I find their building blocks to be much neater compared to the React based Next.js.
25 lines
500 B
JavaScript
25 lines
500 B
JavaScript
self.addEventListener("push", function (event) {
|
|
console.log(event);
|
|
if (!event.data)
|
|
return;
|
|
|
|
const payload = event.data.json();
|
|
const { body, icon, image, badge, url, title } = payload;
|
|
const notificationTitle = title ?? "No title";
|
|
const notificationOptions = {
|
|
body,
|
|
icon,
|
|
image,
|
|
data: {
|
|
url,
|
|
},
|
|
badge,
|
|
};
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(notificationTitle, notificationOptions)
|
|
.then(() => {
|
|
console.log("Web push delivered");
|
|
})
|
|
);
|
|
});
|