位置: IT常识 - 正文

vue通知提醒消息(vue 提示)

编辑:rootadmin
vue通知提醒消息

目录

前言

一、Notification

二、Notification引用

           1.全局引用

           2.单独引用

三、参数说明

四、简单案例 

五、项目实战

1、定义全局Notification。

2、Websocket实时接收通知。

3、消息通知


前言

推荐整理分享vue通知提醒消息(vue 提示),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue系统通知,vue推送消息,vue 消息通知,vue 提示,vue消息框,vue 消息通知,vue 消息通知,vue 消息通知,内容如对您有帮助,希望把文章链接给更多的朋友!

最近有个项目需求就是在客户端的右上角要实时展示提醒消息,下面来看下简单的实现步骤

一、Notification

这是基于悬浮出现在页面角落,显示全局的通知提醒消息。这个elmennt-ui组件可以实现我们上面的功能。

二、Notification引用1.全局引用vue通知提醒消息(vue 提示)

element 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。

2.单独引用

import { Notification } from 'element-ui';

此时调用方法为 Notification(options)。我们也为每个 type 定义了各自的方法,如 Notification.success(options)。并且可以调用 Notification.closeAll() 手动关闭所有实例。

三、参数说明

四、简单案例 

右上角就会弹出我们写的html代码段是不是特别简单

<template> <el-button plain @click="open"> 使用 HTML 片段 </el-button></template><script> export default { methods: { open() { this.$notify({ title: 'HTML 片段', dangerouslyUseHTMLString: true, message: '<strong>这是 <i>HTML</i> 片段</strong>' }); } } }</script>五、项目实战

这里大概说一下我的流程,我这里需要建立Websocket连接,服务器实时推送信息给客户端在右上角展示,这里需要用到Websocket以及本章学的通知。Websocket在前一章有讲。案例仅供参考。

1、定义全局Notification。/* 全局Notification */Vue.prototype.$baseNotify = (message, title, type, position) => {Notification({title: title,message: message,position: position || 'top-right',type: type || 'success',duration: messageDuration,})}2、Websocket实时接收通知。initWebSocket() { const token = getAccessToken() const wsurl = `${this.troubelUrl}?code=trouble&token=${token}` this.twebsock = new WebSocket(wsurl) this.twebsock.onmessage = this.websocketonmessage this.twebsock.onopen = this.websocketonopen this.twebsock.onerror = this.websocketonerror this.twebsock.onclose = this.websocketclose }, websocketonopen() { //webscoket定时心跳 this.troubleTimer = setInterval(() => { let pageUrl = window.location.hash if (pageUrl !== '' && pageUrl !== '#/login') { this.websocketsend('heartbeat') } }, 50000) console.log('数据发送...') }, websocketonerror(e) { //连接建立失败重连 setTimeout(() => { this.initWebSocket() }, 10000) console.log('故障连接出错~') }, websocketonmessage(evt) { var monitorData = evt.data monitorData = JSON.parse(monitorData) this.switchOther(this.troublePush, monitorData) }, //根据数据判断进行弹框(紧急呼叫,长时间关人) switchOther(switchValue, monitorData) { if (switchValue === true || switchValue === 'true') { this.handleOpen(monitorData) } }, websocketsend(data) { this.twebsock.send(data) }, websocketclose(e) { if (this.twebsock == null) { return } this.twebsock.close() this.twebsock = null clearInterval(this.troubleTimer) console.log('故障推送关闭~') },3、消息通知 //monitorItem取的前面Websocket返回回来的值 handleOpen(monitorItem) { this.openDialogflase = true const h = this.$createElement let notify = this.$notify({ title: monitorItem.troubleType, message: h('p', null, [ h( 'span', { style: { display: 'inline-block', margin: '0 0 10px 0', }, }, `${monitorItem.projectName}-${monitorItem.useCode}` ), h( 'p', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', margin: '0 0 5px 0', }, }, [ h('span', null, monitorItem.duration), h( 'span', { style: { color: '#efefef', }, }, monitorItem.fromType ), ] ), h('p', null, monitorItem.address), h( 'button', { style: { padding: '5px 20px', fontSize: '14px', borderRadius: '4px', color: '#fff', background: '#ff575a', border: 'none', margin: '10px 10px 0 0', display: 'inline-block', }, on: { click: this.clickBtn.bind(this, monitorItem), }, }, '查看详情' ), h( 'button', { style: { padding: '5px 20px', fontSize: '14px', borderRadius: '4px', color: '#fff', background: '#ff575a', border: 'none', margin: '10px 10px 0 0', display: 'inline-block', }, on: { click: this.handleShi.bind(this, monitorItem), }, }, '双向视频' ), h( 'button', { style: { padding: '5px 20px', fontSize: '14px', borderRadius: '4px', color: '#fff', background: '#ff575a', border: 'none', margin: '10px 0 0 0', display: 'inline-block', }, on: { click: this.handleQuXiao.bind(this, monitorItem), }, }, '取消' ), ]), duration: 0, showClose: false, }) //将通知实例放入 this.notifications[monitorItem.orderKey] = notify this.handleAudio() }, //关闭当前故障弹框 handleQuXiao(monitorItem) { this.openDialogflase = false this.notifications[monitorItem.orderKey].close() delete this.notifications[monitorItem.orderKey] }, //关闭所有弹窗 closeAll() { let vue = this for (let key in vue.notifications) { vue.notifications[key].close() delete vue.notifications[key] } },
本文链接地址:https://www.jiuchutong.com/zhishi/296046.html 转载请保留说明!

上一篇:JavaWeb简易复习手册(javaweb知识点汇总)

下一篇:GPT-4介绍&api申请(Chatgpt plus)(gpt3 api)

  • 免税肉类主要品种目录
  • 特定业务计算的应纳税所得额
  • 已交增值税如何做账
  • 混合销售行为如何缴纳增值税税率
  • 装修工程一切险
  • 金税盘地区编号淄博
  • 土地增值税计税依据
  • 其他综合收益税后净额影响净利润吗
  • 新会计准则下长期股权投资的变化
  • 管理费用和财务费用算营业成本吗
  • 公司合并后业务怎么办
  • 收到小微企业补贴如何做账
  • 连续3个月增值税留抵
  • 计提汇算清缴涉及到不是当年费用怎么记账
  • 低价购买债权后可否向债务人全额主张债务
  • 企业收到供货单位提供的材料
  • 生产成本中材料款年末要全部结转吗
  • 收回税款 会计分录
  • 2019年城建税减免政策
  • 所有者权益为什么是负债
  • 取得高新技术企业
  • 法人股东分红如何申报所得税
  • 幼儿园开发成本
  • 如何彻底删除QQ频道私信
  • getparameter报错
  • 报废资产未及时核销
  • 固定资产进项发票
  • 兼职人员工资如何扣税
  • win10升级win11报错
  • kb4592440安装失败
  • mom.exe是什么进程
  • php图片下载本地功能
  • 工行对公贷款利息扣除时间
  • 微信小程序登录后端
  • Yii2实现ajax上传图片插件用法
  • laravel datatable
  • 纳汉双语
  • fastjson 解析
  • gpt gtp
  • vue路由用法
  • php中array用法
  • 基于php判断客户是否存在
  • phpcms rce
  • 异地预缴的附加税在申报税时会抵消掉么
  • 营业外支出的计算公式
  • 会计需要装订资料有哪些
  • 个人所得税有哪些项目
  • 出售无形资产和固定资产计入什么科目
  • 房产税的纳税义务人是征税范围内房屋产权所有人
  • 固定资产计提折旧凭证怎么做
  • 建筑企业预缴税
  • 固定资产赠送后怎么做凭证
  • 企业投资期货亏损能抵税么
  • 预付一年房租费的会计分录
  • 收到发票就是付款了吗
  • 跨年度退货可以不退款吗
  • 咨询服务费如何合理避税
  • 应收应付的意思
  • 在sql server中关于数据库的说法正确的是
  • linux rpm包怎么安装
  • 该怎么配置
  • linux常用小技巧
  • 让你的好朋友评价你图片
  • xp系统怎么装系统教程
  • windowsxpsp3是什么版
  • 防止非法使用计算机,可口令
  • nodejs支付宝支付
  • perl读取文件内容逐行处理
  • opengl使用教程
  • dos跳转到指定目录
  • android开发范例实战宝典
  • javascript 进阶篇1 正则表达式,cookie管理,userData
  • 用js改变css样式
  • 深入浅出css
  • 联华超市华联超市哪个厉害
  • 深圳市福田区税务局电话
  • 江西省企业社会保险费缴费指南
  • 河北国家税务局官网站
  • 长沙个体户缴纳个税
  • 国税工作人员工资标准
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设