Created
June 2, 2018 04:24
-
-
Save SoarLin/ea1c17d2e981886d072499355e897471 to your computer and use it in GitHub Desktop.
Vue Project use 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
const FCMconfig = { | |
apiKey: 'YOUR_API_KEY', | |
authDomain: 'YOUR_DOMAIN', | |
databaseURL: 'https://<YOUR_PROJECT_ID>.firebaseio.com', | |
projectId: 'YOUR_PROJECT_ID', | |
storageBucket: '<YOUR_PROJECT_ID>.appspot.com', | |
messagingSenderId: 'YOUR_SENDER_ID' | |
} | |
firebase.initializeApp(FCMconfig) | |
Vue.prototype.$messaging = firebase.messaging() | |
Vue.prototype.$messaging.usePublicVapidKey('<YOUR_PUBLIC_VAPID_KEY>') | |
navigator.serviceWorker.register('/static/firebase-messaging-sw.js') | |
.then((registration) => { | |
Vue.prototype.$messaging.useServiceWorker(registration) | |
}).catch(err => { | |
console.log(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment