【问题标题】:VueJS App and Firebase messaging errorVueJS 应用程序和 Firebase 消息传递错误
【发布时间】:2018-09-30 20:24:13
【问题描述】:

嗨,我试图让推送通知适用于我的应用程序,但我似乎无法让它与我的 Vue 应用程序一起运行

我不断收到此错误:

消息:我们无法注册默认服务工作者。注册 ServiceWorker 失败:脚本具有不受支持的 MIME 类型 ('text/html')。 (消息/失败的serviceworker-registration)

我不知道怎么处理。

这是我的 Main.js:

let config = {
 apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
 authDomain: 'vue-notify.firebaseapp.com',
 databaseURL: 'https://vue-notify.firebaseio.com',
 projectId: 'vue-notify',
 storageBucket: 'vue-notify.appspot.com',
 messagingSenderId: 'xxxxxxxxxxxxxxxxxxxxxx'
}

firebase.initializeApp(config)

这是我调用 firebase.messaging() 的组件中的函数

subscribe () {
  firebase.messaging().requestPermission().then(() => firebase.messaging().getToken())
    .then((token) => console.log(token))
    .catch((err) => console.log(err))
}

很高兴知道我需要做什么

【问题讨论】:

标签: firebase vue.js push-notification firebase-cloud-messaging


【解决方案1】:

根据documentationthis answerthis one,您似乎必须将配置放在公共目录中的firebase-messaging-sw.js 中。

【讨论】:

    猜你喜欢
    • 2020-12-31
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 2021-07-20
    • 1970-01-01
    相关资源
    最近更新 更多