Created
August 11, 2020 07:57
-
-
Save daubattu/bb21912fc17ea45cb4b4349b1d5befb5 to your computer and use it in GitHub Desktop.
How to push notification in NuxtJS with Firebase Cloud Messaging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template></template> | |
<script> | |
import firebase from '../plugins/firebase'; | |
export defautl { | |
created() { | |
const messaging = firebase.messaging(); | |
messaging | |
.requestPermission() | |
.then(() => { | |
console.log('Notification permission granted.'); | |
return messaging.getToken(); | |
}) | |
.then((token) => { | |
// You update this token for server by call api | |
console.log('The token is: ', token); | |
}) | |
.catch(function (err) { | |
console.log('Unable to get permission to notify.', err); | |
}); | |
messaging.onMessage(function (payload) { | |
console.log('Message received. ', payload); | |
}); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you share plugins/firebase.js ?