亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知

 更新時(shí)間:2019年08月17日 10:45:43   作者:會(huì)飛的joy  
這篇文章主要介紹了vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知

使用element-ui中的Notification,只有一個(gè)message屬性是有很大的操作空間,其余的都是寫(xiě)死的,無(wú)法進(jìn)行擴(kuò)展,達(dá)不到想要的效果。所以只能在message上下功夫。

在element-ui官方文檔中可以看到Notification中的message屬性是可以處理VNode的所以我們可以使用VNode來(lái)達(dá)到我們需要的效果。

如何關(guān)閉通知呢?

當(dāng)創(chuàng)建通知的時(shí)候,會(huì)返回該通知的實(shí)例,通過(guò)該實(shí)例的close方法可以將通知關(guān)閉。

那么當(dāng)有多個(gè)通知顯示在屏幕上時(shí),如何關(guān)閉特定彈窗的呢?

創(chuàng)建一個(gè)字典,字典的key是message的Id,value是顯示該消息的通知的實(shí)例。從而可以關(guān)閉特定的通知。代碼如下。

import mainTable from './mixin/mainTable';
import systemMenu from './template/system-menu';
import headerRow from './template/header';
export default {
  name: 'xxxxx',
  data() {
    return {
      //使用messageId作為彈窗的key,用來(lái)獲取彈窗的實(shí)例,以對(duì)對(duì)應(yīng)彈窗進(jìn)行操作
      notifications: {}
    };
  },
  mounted() {
    this.$messageWebsocket.websocketApi.initWebSocket(this.$store.state.login.userInfo.userInfo.id, this.openMessageTips);
  },
  methods: {
    //關(guān)閉單個(gè)通知
    closeNotification(id, operateCode, message){
      this.notifications[message.messageId].close();
      delete this.notifications[message.messageId];
    },
    //關(guān)閉所有通知
    closeAllNotification(){
      let _this = this;
      for (let key in _this.notifications) {
        _this.notifications[key].close();
        delete _this.notifications[key];
      }
    },
    //打開(kāi)一個(gè)新的通知
    openMessageTips(message){
      let _this = this;
      this.closeAllNotification();
      let notify = this.$notify({
        title: '三高協(xié)診消息',
        position: 'bottom-right',
        showClose: false,
        dangerouslyUseHTMLString: true,
        message: this.$createElement('div', null,
          [
            this.$createElement('div', null, [this.$createElement('span', null, message.content)]),
            this.$createElement('div', null,
              [
                this.$createElement(
                  'button',
                  {
                    style: {
                      padding: '10px 18px',
                      margin: '10px 12px 0px 2px',
                      textAlign: 'center',
                      textDecoration: 'none',
                      display: 'inline-block',
                      webkitTransitionDuration: '0.4s',
                      transitionDuration: '0.4s',
                      cursor: 'pointer',
                      backgroundColor: 'white',
                      color: 'black',
                      border: '2px solid #e7e7e7',
                    },
                    on: {
                      mouseout: function(e){
                        e.target.style.backgroundColor = 'white';
                      },
                      mouseover: function(e){
                        e.target.style.backgroundColor = '#e7e7e7'
                      },
                      click: _this.closeNotification.bind(_this, 1, 1, message)
                    }
                  },
                  "查看"
                ),
                this.$createElement(
                  'button',
                  {
                    style: {
                      padding: '10px 18px',
                      margin: '10px 2px 0px 12px',
                      textAlign: 'center',
                      textDecoration: 'none',
                      display: 'inline-block',
                      webkitTransitionDuration: '0.4s',
                      transitionDuration: '0.4s',
                      cursor: 'pointer',
                      backgroundColor: 'white',
                      color: 'black',
                      border: '2px solid #e7e7e7',
                    },
                    on: {
                      //鼠標(biāo)移出的回調(diào)
                      mouseout: function(e){
                        e.target.style.backgroundColor = 'white';
                      },
                      //鼠標(biāo)移入的回調(diào)
                      mouseover: function(e){
                        e.target.style.backgroundColor = '#e7e7e7'
                      },
                      click: _this.closeNotification.bind(_this, 1, 2, message)
                    }
                  },
                  "稍后提醒(五分鐘后)"
                )
              ]
            )
          ]
        ),
        duration: 0,
      });
      //將messageId和通知實(shí)例放入字典中
      this.notifications[message.messageId] = notify;
    }
  }
};

總結(jié)

以上所述是小編給大家介紹的vue 使用element-ui中的Notification自定義按鈕并實(shí)現(xiàn)關(guān)閉功能及如何處理多個(gè)通知,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

最新評(píng)論