浏览器通知未出现

时间:2018-11-06 04:26:15

标签: javascript notifications

我正在尝试使用以下代码显示通知:

if(Notification.permission === 'granted' && !this._active) {
    let n = new Notification(this._activeContact.name,{
        icon : this._activeContact.photo,
        body : data.content
});

但是什么也没出现! 我已经应要求授予了权限!

顺便说一下,我有一个功能要求浏览器授予权限

checkNotifications(){
    // debugger
    if (typeof Notification === 'function'){
        if (Notification.permission !== 'granted'){
            this.el.alertNotificationPermission.show()
        } else {
            this.el.alertNotificationPermission.hide()
        }

        this.el.alertNotificationPermission.on('click', e=> {
            Notification.requestPermission(permission => {
                if (permission === 'granted') {
                    this.el.alertNotificationPermission.hide()
                    console.info('notificações permitidas!')
                }
            })
        })
    }
}

并且无法正常工作!

0 个答案:

没有答案