简体   繁体   English

firebase.messaging:无法读取未定义的属性“getNotificationPermission_”

[英]firebase.messaging: Cannot read property 'getNotificationPermission_' of undefined

Im trying to add firebase for webpush in one old project.我试图在一个旧项目中为 webpush 添加 firebase。

There are require.js and also I cant use node.有require.js,我也不能使用节点。 So I copy firebase app and firebase messaging from firebase cdn (www.gstatic.com) and import them in project.所以我从 firebase cdn (www.gstatic.com) 复制firebase 应用程序和 firebase消息并将它们导入到项目中。

But when I call messaging method requestPermission() it outputs in console Cannot read property 'getNotificationPermission_' of undefined .但是,当我调用消息传递方法requestPermission() 时,它在控制台中输出无法读取 undefined 的属性“getNotificationPermission_”

Firebase losing context, but if I change all this for explicit context assignment, like let self = this , everything works fine. Firebase 丢失上下文,但是如果我为显式上下文分配更改所有这些,例如let self = this ,则一切正常。

How should I import firebase for its performance?我应该如何导入 firebase 以提高其性能?

For anyone, who faced same problem - I find the with epmty: scheme in requirejs .对于任何面临同样问题的人 - 我在 requirejs 中找到了 with epmty: 方案 This GitHub issue may help you https://github.com/firebase/firebase-js-sdk/issues/1569这个 GitHub 问题可能对你有帮助https://github.com/firebase/firebase-js-sdk/issues/1569

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM