浏览器推送pc&手机端,可能会有兼容性问题

// test服务器推送
const pushMessage = () => {
  if (window.Notification) {
        console.log("支持弹出框")
      } else {
        // 不支持
        console.log("不支持")
        alert("当前浏览器不支持弹出消息通知哦!")
      }
      if(window.Notification && Notification.permission !== "denied") {
        Notification.requestPermission(function(status) {
          if (status === "granted") {
            var n = new Notification('遵师维小宝', {
              body: '有用户提交报修故障了!',
            });
          } else {
            alert("当前的浏览器不支持消息通知!!!");
          }
        });
      }
}


onMounted(() => {
  setTimeout(() => {
    pushMessage()
  }, 5000)
})

本地测试没问题,上线之后必须是https

方法二:

附上官网:Installing | Push v1.0

在Vue中安装npm install push.js --save

在所需要的Vue页面引入使用

import Push from 'push.js'
 
 
export default {
  name: "recordAll",
  methods: {
    //推送弹框消息
    pushMessage(){
       Push.Permission.request();
      Push.create("遵师维小宝", {
        body: "我来了!!!",
        requireInteraction: true,
        //icon: '/icon.png',
         timeout: 600000,
      });
  
    },
  mounted(){
     this.pushMessage();
  },
}

猜你喜欢

转载自blog.csdn.net/qq_48795670/article/details/132139469