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

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

如何关闭通知呢?

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

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

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

  1. import mainTable from './mixin/mainTable';
  2. import systemMenu from './template/system-menu';
  3. import headerRow from './template/header';
  4.  
  5. export 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. };

vue 使用element-ui中的Notification自定义按钮并实现关闭功能以及如何处理多个通知的更多相关文章

  1. 有关vue中用element ui 中的from表单提交json格式总是有冒号的问题解决办法

    因为后台要求要传递JSON格式的数据给他,然后我转了之后总是多了冒号,后来又看了自己的报错,原来是报了404错误,说明路径找不到, 数据格式 后来发现怎么都不行了,然后突然查看了报错报的是404,说明 ...

  2. 关于Element UI中页面样式小问题

    一,修改组件dialog窗口的大小 二,在我使用upload组件上传一张美女图片时,发现当预览图片时,图片是灰色的,点击一下才会变亮,这种效果使我很不舒服,于是我通过添加下面的一条样式,问题解决了(可 ...

  3. 关于vue.js element ui 表单验证 this.$refs[formName].validate()的问题

        方法使用前需了解: 来自”和“小编的小提示: 首先打印一下this.$refs[formName],检查是否拿到了正确的需要验证的form. 其次在拿到了正确的form后,检查该form上添加 ...

  4. element ui中的一些小技巧

    最近写公司的项目,这项目是vue和element ui搭建的, 做的是一套电力系统的管理平台.  遇到一个小麻烦,用过element ui 的都知道,使用element ui 弹框,点击空白处,默认是 ...

  5. 关于Element UI中select组件中遇到的问题

    问题一:在使用select组件设置多选功能后,窗口抖动问题? 详细描述:在我使用select做多选的功能时出现了窗口抖动的问题,测试的时候发现,在有些人的电脑上抖动,有些人的电脑上不抖,找了很多文档, ...

  6. Element UI 中组件this.$message报错

    最近在做毕设的时候,用Element UI中的消息提示message一直报以下的错误: 展示的效果也不好看,没有图标什么的: 但我明明有在main.js引入了element-ui 呀,因为毕设时间很赶 ...

  7. vue(element)中使用codemirror实现代码高亮,代码补全,版本差异对比

    vue(element)中使用codemirror实现代码高亮,代码补全,版本差异对比 使用的是vue语言,用element的组件,要做一个在线编辑代码,要求输入代码内容,可以进行高亮展示,可以切换各 ...

  8. 通过WPF中UserControl内的按钮点击关闭父窗体

    原文:通过WPF中UserControl内的按钮点击关闭父窗体 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/m0_37591671/article ...

  9. vue+element ui中select组件选择失效问题原因与解决方法

    codejing 2020-07-10 09:13:31  652  收藏 分类专栏: Web Vue Element UI 版权 .当表单form赋完值后,如果后续又对form中某一属性值进行操作如 ...

随机推荐

  1. 【BZOJ2409】 地下车会

    Description 小Y喜欢速度与激情,于是他参加了地下车会.  地下车会设有N 个分赛区,M种赛事.每个分赛区有C[i]场比赛.由于地下车会经营者想要赚到更多的钱,规定小 Y 必须参加某一些赛区 ...

  2. 网页结构树DOM

    引入 window对象 所有浏览器都支持 window 对象.它表示浏览器窗口. *如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为 ...

  3. 3D Computer Grapihcs Using OpenGL - 19 Vertex Array Object(顶点数组对象)

    大部分OpenGL教程都会在一开始就讲解VAO,但是该教程的作者认为这是很不合理的,因为要理解它的作用需要建立在我们此前学过的知识基础上.因此直到教程已经进行了一大半,作者才引入VAO这个概念.在我看 ...

  4. c++函数相关

    1,内连函数 inline 返回值类型 函数名(形参列表) 普通函数成为内连函数:在普通函数声明之前加上inline 成员函数成为内连函数:在类中定义的函数全部默认为内连函数,可以显示加上inline ...

  5. legend3---OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054

    legend3---OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 一.总结 一句话总结: 解决方法:多试几次,实在不行就手动下载 1.homeste ...

  6. LR报:Error 27796 Failed to connect to server

    原错误信息: Action.c(58): Error -27796: Failed to connect to server "10.1.44.68:7013": [10048] ...

  7. leetcode-mid-backtracking -46. Permutations-NO

    mycode 没有通过,其实只需要把temp.append改为temp+[nums[i]]即可 def permute(nums): def dfs(res,nums,temp): print(num ...

  8. 2、Shiro的认证

    Shiro的认证流程大体可以参考下面这幅图: 但是没有接触过shiro的同学看到上面的图片也不明白,下面我们来在代码中尝试体验Shiro的认证过程: 1.新建一个SpringBoot项目项目结构如下: ...

  9. mysql添加字段索引失败 BLOB/TEXT column 'col2' used in key specification without a key length

    看了下该表的数据结构发现col2字段类型是text ,查询了下发现是:MySQL只能将BLOB/TEXT类型字段设置索引为BLOB/TEXT数据的钱N个字符.索引指定下col2的长度就可以了 : al ...

  10. centos7 ngxin启动失败:Job for nginx.service failed(80端口被占用的解决办法)

    问题描述:(flaskApi) [root@67 flaskDemo]# service nginx start Redirecting to /bin/systemctl start nginx.s ...