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

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

如何关闭通知呢?

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

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

创建一个字典,字典的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: '消息',
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自定义按钮并实现关闭功能以及如何处理多个通知的更多相关文章

  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. express 设置 cookie 以及 httpOnly

    权限控制基本 cookie 在 express 中引入 cookie-parser const express = require('express') const cookieParser = re ...

  2. java web程序上传文件,浏览器显示连接被重置

    上传文件时,到13%时浏览器显示连接被重置如图: 参考网上很多方法 比如设置server.xml 的相应大小.时间,然并没有解决问题 connectionTimeout="2000000&q ...

  3. [LeetCode]-DataBase-Nth Highest Salary

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  4. TCP与UDP的对比分析

    转自该地址:https://blog.csdn.net/birdie_l/article/details/78067896 TCP: 优点:可靠 稳定 TCP的可靠体现在TCP在传输数据之前,会有三次 ...

  5. Oracle诊断:drop table失败[转]

    转: From <http://blog.csdn.net/cyxlxp8411/article/details/7775113> 今天在drop一张表的时候报ORA-00054错误 SQ ...

  6. 追加环境变量到Path

    @echo off setlocal enabledelayedexpansion ::使用方法: :: "C:\WINDOWS" :: "C:\jar" SE ...

  7. 如何解决两个相邻的span中间有空隙

    span中间不要有换行.或者空格 或者在样式上加上float:left

  8. Spring boot 自定义一个starter pom

    用过springboot的自动配置会觉得非常方便,我们完全可以自己写一个starter pom,这样不仅可以有自动配置功能,而且具有更通用的的耦合度低的配置, 新建一个starter的maven项目, ...

  9. Maven聚合和继承

    一.建立以pom为packaging的项目为,然后再以这一个项目为parent project来聚合其他子项目         新建立一个以pom的项目 改写pom文件,依赖web-common,这样 ...

  10. 用ajax提交请求,预期Json返回 406错误的解决办法!

    正常情况下在Controller端已经配置好了 @ResponseBody    @RequestMapping  返回Json格式数据 发生406错误 ,应该检查提交的请求路径是否含有 .html ...