国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 11:01:08
字體:
來源:轉載
供稿:網(wǎng)友

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

使用element-ui中的Notification,只有一個message屬性是有很大的操作空間,其余的都是寫死的,無法進行擴展,達不到想要的效果。所以只能在message上下功夫。

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

如何關閉通知呢?

當創(chuàng)建通知的時候,會返回該通知的實例,通過該實例的close方法可以將通知關閉。

那么當有多個通知顯示在屏幕上時,如何關閉特定彈窗的呢?

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

import mainTable from './mixin/mainTable';import systemMenu from './template/system-menu';import headerRow from './template/header';export default {  name: 'xxxxx',  data() {    return {      //使用messageId作為彈窗的key,用來獲取彈窗的實例,以對對應彈窗進行操作      notifications: {}    };  },  mounted() {    this.$messageWebsocket.websocketApi.initWebSocket(this.$store.state.login.userInfo.userInfo.id, this.openMessageTips);  },  methods: {    //關閉單個通知    closeNotification(id, operateCode, message){      this.notifications[message.messageId].close();      delete this.notifications[message.messageId];    },    //關閉所有通知    closeAllNotification(){      let _this = this;      for (let key in _this.notifications) {        _this.notifications[key].close();        delete _this.notifications[key];      }    },    //打開一個新的通知    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: {                      //鼠標移出的回調                      mouseout: function(e){                        e.target.style.backgroundColor = 'white';                      },                      //鼠標移入的回調                      mouseover: function(e){                        e.target.style.backgroundColor = '#e7e7e7'                      },                      click: _this.closeNotification.bind(_this, 1, 2, message)                    }                  },                  "稍后提醒(五分鐘后)"                )              ]            )          ]        ),        duration: 0,      });      //將messageId和通知實例放入字典中      this.notifications[message.messageId] = notify;    }  }};

總結

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沈阳市| 郁南县| 阿合奇县| 辽宁省| 阿鲁科尔沁旗| 临潭县| 公安县| 久治县| 合山市| 彭山县| 铜梁县| 米脂县| 剑川县| 综艺| 启东市| 高雄市| 田东县| 若羌县| 白玉县| 东阳市| 湖南省| 兴隆县| 武宣县| 蛟河市| 全州县| 绥滨县| 灵璧县| 新余市| 会东县| 都兰县| 鹤壁市| 津南区| 玉树县| 饶阳县| 五原县| 绥芬河市| 渝北区| 体育| 安吉县| 天水市| 灌南县|