应无所住,而生其心
排名
1
文章
860
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

vue element ui 提示,通知 Notification增加关闭按钮。vue动态创建按钮,并添加事件。minxins

4126人阅读 2022/7/1 12:57 总访问:5182874 评论:0 收藏:0 手机
分类: 前端

element ui Notification默认没有关闭按钮这些,但是内容可以写html就可以进行一些自定义了。实现效果如下:

实现

在src下面创建一个minxins文件夹,创建一个my_notification.js加入封装代码,方便重用

  1. export default {
  2. data() {
  3. return {
  4. //使用messageId作为弹窗的key,用来获取弹窗的实例,以对对应弹窗进行操作
  5. notifications: {},
  6. };
  7. },
  8. methods: {
  9. //关闭单个通知
  10. closeNotification(message) {
  11. this.notifications[message.messageId].close();
  12. delete this.notifications[message.messageId];
  13. },
  14. //打开一个新的通知
  15. openMessageTips(title = "消息提醒", message) {
  16. let _this = this;
  17. // this.closeAllNotification();
  18. let notify = this.$notify({
  19. title: title,
  20. // position: 'bottom-right',
  21. // showClose: false,
  22. dangerouslyUseHTMLString: true,
  23. message: this.$createElement("div", null, [
  24. this.$createElement("div", null, [
  25. this.$createElement(
  26. "span",
  27. { style: { color: "teal" } },
  28. message.content
  29. ),
  30. ]),
  31. this.$createElement("div", null, [
  32. this.$createElement(
  33. "button",
  34. {
  35. style: {
  36. padding: "7px 13px",
  37. margin: "10px -20px 0px 0px",
  38. textAlign: "center",
  39. textDecoration: "none",
  40. display: "inline-block",
  41. webkitTransitionDuration: "0.4s",
  42. transitionDuration: "0.4s",
  43. cursor: "pointer",
  44. backgroundColor: "white",
  45. color: "black",
  46. border: "2px solid #e7e7e7",
  47. borderRadius: "4px",
  48. fontSize: "14px",
  49. color: "#555",
  50. float: "right",
  51. },
  52. on: {
  53. mouseout: function (e) {
  54. e.target.style.backgroundColor = "white";
  55. },
  56. mouseover: function (e) {
  57. e.target.style.backgroundColor = "#e7e7e7";
  58. },
  59. // click: () => { alert(11) }
  60. click: _this.closeNotification.bind(_this, message),
  61. },
  62. },
  63. "关闭"
  64. ),
  65. ]),
  66. ]),
  67. duration: 0,
  68. });
  69. // 将messageId和通知实例放入字典中
  70. this.notifications[message.messageId] = notify;
  71. },
  72. },
  73. };

使用

在需要使用的地方引用封装的js:

  1. import minxins from "@/minxins/my_notification";

然后加入引入的内容

  1. mixins: [minxins],

然后调用方法即可:

  1. mounted() {
  2. this.openMessageTips("特别提醒",{ content: "[张康]老师,截止[2022-06-30 11:14]你负责的课程系统综合完成率[98.02%],校排名[1],集团排名[29]", messageId: "sdfcsdf" })
  3. // 默认查询未读的数据
  4. this.getMessage(1, 0)
  5. },

封装的地方关闭按钮加一个回调函数,用来处理关闭后的事情

  1. export default {
  2. data() {
  3. return {
  4. //使用messageId作为弹窗的key,用来获取弹窗的实例,以对对应弹窗进行操作
  5. notifications: {},
  6. };
  7. },
  8. methods: {
  9. //关闭单个通知
  10. closeNotification(message,callback) {
  11. this.notifications[message.messageId].close();
  12. delete this.notifications[message.messageId];
  13. callback(message.messageId)
  14. },
  15. //打开一个新的通知
  16. openMessageTips(title = "消息提醒", message,callback) {
  17. let _this = this;
  18. // this.closeAllNotification();
  19. let notify = this.$notify({
  20. title: title,
  21. // position: 'bottom-right',
  22. // showClose: false,
  23. dangerouslyUseHTMLString: true,
  24. message: this.$createElement("div", null, [
  25. this.$createElement("div", null, [
  26. this.$createElement(
  27. "span",
  28. { style: { color: "teal" } },
  29. message.content
  30. ),
  31. ]),
  32. this.$createElement("div", null, [
  33. this.$createElement(
  34. "button",
  35. {
  36. style: {
  37. padding: "5px 9px",
  38. margin: "10px -20px 0px 0px",
  39. textAlign: "center",
  40. textDecoration: "none",
  41. display: "inline-block",
  42. webkitTransitionDuration: "0.4s",
  43. transitionDuration: "0.4s",
  44. cursor: "pointer",
  45. backgroundColor: "white",
  46. color: "black",
  47. border: "2px solid #e7e7e7",
  48. borderRadius: "4px",
  49. fontSize: "14px",
  50. color: "#666",
  51. float: "right",
  52. },
  53. on: {
  54. mouseout: function (e) {
  55. e.target.style.backgroundColor = "white";
  56. },
  57. mouseover: function (e) {
  58. e.target.style.backgroundColor = "#e7e7e7";
  59. },
  60. click: _this.closeNotification.bind(_this, message,callback),
  61. },
  62. },
  63. "关闭"
  64. ),
  65. ]),
  66. ]),
  67. duration: 0,
  68. });
  69. // 将messageId和通知实例放入字典中
  70. this.notifications[message.messageId] = notify;
  71. },
  72. },
  73. };

比如在关闭按钮中处理一下消息让消息变为已读

  1. // 直接弹出通知
  2. for (let index = 0; index < taskMessageList.length; index++) {
  3. setTimeout(() => {
  4. const element = taskMessageList[index]
  5. _this.openMessageTips("特别提醒",{ content: element.messageContent, messageId: element.id },(msid)=>{
  6. // alert("点击关闭了:"+msid)
  7. // 关闭的时候调用后台接口,把消息标记为已读
  8. this.$http.post('/education/api/TaskMessage/UpdateTaskMessageIsRead', { Id: msid, IsRead: 1 })
  9. })
  10. }, index * 500)
  11. }

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

vue-element-admin左边树形右边格子的布局。vue element ui模板。树形tree 动态自适应屏幕高度

[TOC]效果如下: 代码如下:&lt;template&gt; &lt;div class=&quot;app-container student-archives&quot;&gt; &l...

vue element ui Collapse 折叠面板默认展开全部

首先去掉accordion属性,不然一次只能选择一个 value绑定一个,然后在使用name指定一个值 这里和上面name指定的值一致就...

vue element ui 日期时间选择器的值传回到后台

直接把时间传回后台去是不行的,element ui 里边的日期组件获取的值默认是返回Date对象的,所以需要格式化一下。官方文档中...

vue element ui select下拉列表。数据绑定基本使用

代码如下: &lt;el-select v-model=&quot;chapterID&quot; style=&quot;width:266px&quot;&gt; &lt;el-option v-f...

vue element ui 中 select 设置支持多选如何给select组件设置默认选中的值

[TOC]select加载的代码如下&lt;template&gt; &lt;el-select size=&quot;small&quot; clearable=&quot;&quot; multiple...

vue element ui table 隐藏显示的时候会跳一下明显的抖动

表格数据由隐藏变为显示的瞬间,页面会有明显抖动的现象。经过一段时间的查找,发现elementui在重新渲染table时td内部的div...

微信密码框提示下载并安装安全控件

登录微信商户平台 输入密码时 一直提示 微信密码框提示下载并安装安全控件 点击下载重复下载了很多次 依然没有用解决办...

IIS网站启动不了错误提示“另一个程序正在使用此文件进程无法访问”

一般情况下是因为端口被占,1、在开始--运行 里面输入cmd点回车,会出现运行窗口。2、在提示符后输入netstat -ano回车,找...

运行ionic出错提示unknown错误

我们在运行ionic程序时经常会看到的这个错误信息终端报错信息:浏览器端报错信息:很明确告诉我们unkown错误,我们找到这个...

发送一个验证码后提示n秒有效

比如300秒有效:varlasttime=300; $(&quot;#checkcodediv&quot;).show(); $(&quot;#checktip&quot;).html(lasttime+&quot...

python 使用pip命令无效提示pip无效

python 使用pip命令无效,提示pip无效首先要确保你安装了pip,其次如果你没有配置环境变量什么的,需要在pip所在目录才能执...

Mono 运行 WinForm 在Ubuntu上班提示缺少程序集

在win寻找对应的程序集拷贝到Ubuntulib/mono/gac下面类似这样看Winform程序缺少什么程序集则拷贝相应程序集注:部分无法拷...

金蝶erp保存提示重复列

出现这个主要是因为标识重复修改一下就阔以保存成功了

解决 gyp: No Xcode or CLT version detected! 错误提示

更新Mac系统后,在用npm安装依赖包的时候总会报这个错误:gyp: No Xcode or CLT version detected!查找了网上的解决办法,...

vs注释失效提示xml注释没有放到有效得元素上造成swagger生成注释也失效

vs注释失效,提示xml注释没有放到有效得元素上,造成swagger生成注释也失效。原因很简单.....方法上面还有一个默认的生成没...