vue 使用element

使用element-ui中的Notification,只有一个message属性是有很大的操作空间,其余的都是写死的,无法进行扩展,达不到想要的效果。所以只能在message上下功夫。

在element-ui官方文档中可以看到Notification中的message属性是可以处理VNode的所以我们可以使用VNode来达到我们需要的效果。

如何关闭通知呢?

当创建通知的时候,会返回该通知的实例,通过该实例的close方法可以将通知关闭。

那么当有多个通知显示在屏幕上时,如何关闭特定弹窗的呢?

创建一个字典,字典的key是message的Id,value是显示该消息的通知的实例。从而可以关闭特定的通知。代码如下。

1import mainTable from './mixin/mainTable'; 2import systemMenu from './template/system-menu'; 3import headerRow from './template/header'; 4 5export default { 6 name: 'xxxxx', 7 data() { 8 return { 9 //使用messageId作为弹窗的key,用来获取弹窗的实例,以对对应弹窗进行操作 10 notifications: {} 11 }; 12 }, 13 mounted() { 14 this.$messageWebsocket.websocketApi.initWebSocket(this.$store.state.login.userInfo.userInfo.id, this.openMessageTips); 15 }, 16 methods: { 17 //关闭单个通知 18 closeNotification(id, operateCode, message){ 19 this.notifications[message.messageId].close(); 20 delete this.notifications[message.messageId]; 21 }, 22 23 //关闭所有通知 24 closeAllNotification(){ 25 let _this = this; 26 for (let key in _this.notifications) { 27 _this.notifications[key].close(); 28 delete _this.notifications[key]; 29 } 30 }, 31 32 //打开一个新的通知 33 openMessageTips(message){ 34 let _this = this; 35 this.closeAllNotification(); 36 let notify = this.$notify({ 37 title: '消息', 38 position: 'bottom-right', 39 showClose: false, 40 dangerouslyUseHTMLString: true, 41 message: this.$createElement('div', null, 42 [ 43 this.$createElement('div', null, [this.$createElement('span', null, message.content)]), 44 this.$createElement('div', null, 45 [ 46 this.$createElement( 47 'button', 48 { 49 style: { 50 padding: '10px 18px', 51 margin: '10px 12px 0px 2px', 52 textAlign: 'center', 53 textDecoration: 'none', 54 display: 'inline-block', 55 webkitTransitionDuration: '0.4s', 56 transitionDuration: '0.4s', 57 cursor: 'pointer', 58 backgroundColor: 'white', 59 color: 'black', 60 border: '2px solid #e7e7e7', 61 }, 62 on: { 63 mouseout: function(e){ 64 e.target.style.backgroundColor = 'white'; 65 }, 66 mouseover: function(e){ 67 e.target.style.backgroundColor = '#e7e7e7' 68 }, 69 click: _this.closeNotification.bind(_this, 1, 1, message) 70 } 71 }, 72 "查看" 73 ), 74 this.$createElement( 75 'button', 76 { 77 style: { 78 padding: '10px 18px', 79 margin: '10px 2px 0px 12px', 80 textAlign: 'center', 81 textDecoration: 'none', 82 display: 'inline-block', 83 webkitTransitionDuration: '0.4s', 84 transitionDuration: '0.4s', 85 cursor: 'pointer', 86 backgroundColor: 'white', 87 color: 'black', 88 border: '2px solid #e7e7e7', 89 }, 90 on: { 91 //鼠标移出的回调 92 mouseout: function(e){ 93 e.target.style.backgroundColor = 'white'; 94 }, 95 //鼠标移入的回调 96 mouseover: function(e){ 97 e.target.style.backgroundColor = '#e7e7e7' 98 }, 99 click: _this.closeNotification.bind(_this, 1, 2, message) 100 } 101 }, 102 "稍后提醒(五分钟后)" 103 ) 104 ] 105 ) 106 ] 107 ), 108 duration: 0, 109 }); 110 //将messageId和通知实例放入字典中 111 this.notifications[message.messageId] = notify; 112 } 113 } 114};
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

前端性能优化 - 雅虎军规

无论是在工作中,还是在面试中,web前端性能的优化都是很重要的,那么我们进行优化需要从哪些方面入手呢?可以遵循雅虎的前端优化35条军规,这样对于优化有一个比较清晰的方向.35条军规1.尽量减少HTTP请求个数——须权衡2.使用CDN(内容分发网络)3.为文件头指定Expires或CacheControl,使内容具有缓存性。4.避免空的