Skip to content

Instantly share code, notes, and snippets.

@SoarLin
Created June 2, 2018 04:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SoarLin/ea1c17d2e981886d072499355e897471 to your computer and use it in GitHub Desktop.
Save SoarLin/ea1c17d2e981886d072499355e897471 to your computer and use it in GitHub Desktop.
Vue Project use firebase cloud messaging
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