vue使用桌面通知

vue使用桌面通知_第1张图片

methods: {
    handleNotice() {
      let that = this
      if (!("Notification" in window)) {
        alert("此浏览器不支持桌面通知!");
      }
      Notification.requestPermission().then(function (result) {
        if (result === "denied") {
            console.log("被拒绝")
            return
        }
        if (result === "default") {
            console.log("默认");
            return;
        }
        that.notifyMsg();
      });
    },
    notifyMsg() { //通知
      const title = "通知栏";
      const options = {
        body: "这是消息主体", // 通知主体
        data:"",
        icon: "https://sponsors.vuejs.org/images/chrome_frameworks_fund.png", // 通知图标
      };
      let notification = new Notification(title, options);
      notification.onclick = () => {
        notification.close(); //关闭通知
      };
    },
  }

你可能感兴趣的:(vue.js,前端,javascript)