created() {if (window.Notification) {// 浏览器通知--window.Notificationif (Notification.permission == "granted") {console.log("允许通知")}else if( Notification.permission != "denied"){console.log("需要通知权限")Notification.requestPermission((permission)=> {});}} else {console.error('浏览器不支持Notification');}},
methods: {popNotice(user, content) {let that = this;if (Notification.permission == "granted") {let notification = new Notification(user, {body: content,icon: logo.png});notification.onclick = function(e) {that.$nextTick(() => {setTimeout(()=>{//具体操作},500);});//可直接打开通知notification相关联的tab窗window.focus();notification.close();};}},
}调用:
this.popNotice('你','show me the code')