FCM 浏览器通知在 Vue 3 中不起作用
这是我的代码。到目前为止,我已经设法让后台通知正常工作。 (Onmessage 不起作用)
"firebase": "^9.6.7",
firebase-messaging-sw.js
null
App.vue
import { initializeApp } from 'firebase/app';
import { getMessaging, getToken, onMessage } from "firebase/messaging";
const firebaseConfig = {
apiKey: "AIzaSyDXnUaeAK",
authDomain: "test-test.firebaseapp.com",
projectId: "test-test",
storageBucket: "test-test.appspot.com",
messagingSenderId: "123456789",
appId: "1:38296:web:j88054626",
measurementId: "X-TEST"
};
initializeApp(firebaseConfig);
const messaging = getMessaging();
getToken(messaging, { vapidKey: 'key' })
.then((currentToken) => {
console.log("currentToken", currentToken);
})
onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
// ...
});
Here's my code. So far I've managed to get the background notification working. (Onmessage not working)
"firebase": "^9.6.7",
firebase-messaging-sw.js
null
App.vue
import { initializeApp } from 'firebase/app';
import { getMessaging, getToken, onMessage } from "firebase/messaging";
const firebaseConfig = {
apiKey: "AIzaSyDXnUaeAK",
authDomain: "test-test.firebaseapp.com",
projectId: "test-test",
storageBucket: "test-test.appspot.com",
messagingSenderId: "123456789",
appId: "1:38296:web:j88054626",
measurementId: "X-TEST"
};
initializeApp(firebaseConfig);
const messaging = getMessaging();
getToken(messaging, { vapidKey: 'key' })
.then((currentToken) => {
console.log("currentToken", currentToken);
})
onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
// ...
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论