位置: 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)

  • 企业季度所得税申报表怎么填写
  • 投资收益所得税前扣除
  • 疫情期间社保单位不交个人吃亏吗
  • 社保可以抵扣什么税
  • 经营成本是营业成本还是营业总成本
  • 企业缴纳增值税后还需缴纳所得税吗
  • 法人可不可以办信用卡
  • 跨区域能领发票吗
  • 对赌协议赢了怎么样
  • 一般纳税人购进免税农产品如何抵扣进项税额
  • 医院外聘专家费用由科室承担吗
  • 财务费用做什么明细账
  • 转让长期股权投资交什么税
  • 购买电脑配件的网址
  • 运输业过路费怎么做账
  • 公司租赁厂房开几个点发票
  • 如何理解消费税的作用
  • 销售费用的运费算不算增值税
  • 资产和利润表的关系
  • 无偿划转净资产为负数的企业账务处理
  • 坏账准备年底有余额吗
  • 汽车修理费抵扣怎么做账
  • 代付给其他供应商货物尾款怎么记账
  • 事业单位 会计
  • 社保费现金收缴管理制度
  • 应付工资薪酬期末应该为0吗
  • win10电脑防火墙如何关闭
  • 小米无线路由器internet黄灯
  • 公司收入算认缴出资吗
  • msxct.exe - msxct是什么进程 有什么用
  • php实战开发教程
  • 在建工程账务核算方法
  • element-ui dialog
  • php与前端交互
  • php解压压缩包
  • 招待费专票可以抵扣进项吗
  • 会计证的作用和用途
  • GCC strict aliasing – 嫉妒就是承认自己不如别人
  • 研发部门的房租物业费进什么科目
  • 增值税进项税加计抵减
  • 分公司开票总公司收款怎么做账
  • 出口未申报如何处理
  • 高新技术企业相关税收政策
  • 个税算错怎么办理退税
  • 建筑企业的收入特点有哪些
  • 企业购房如何入账
  • sql server的go
  • 小型企业需要给员工买社保吗
  • 企业计提五险一金会计分录怎么写
  • 幼儿园账务处理实务
  • 购销合同上没有金额,怎么写比较好
  • 三栏明细账本怎样填写
  • 针对收入未申报的问题
  • 小规模其他业务收入交多少税率
  • 报销单与发票金额不符看什么
  • mysql zip archive 版本(5.7.19)安装教程详细介绍
  • MAC怎么将单独一个应用静音
  • windows10预览版怎么样
  • m1 macbook压缩能力
  • linux网络管理及应用
  • 如何安装win95系统
  • win 8怎么样
  • 进程process.acore已停止怎么办
  • host文件没有
  • win7文件夹怎么显示大小
  • win8如何激活
  • perl语句
  • 原生javascript开发
  • python中print函数的end参数
  • jquery查找方法
  • 全面解析日本失去的十年
  • javascript概述及作用
  • javascript教程
  • python修改图片背景
  • 支付水电费的增值税税率文件
  • 总分机构在同一县城企业所得税需要预交吗
  • 税务处理决定书属于行政处罚吗
  • 竣工交付的资产有哪几种
  • 地税局社保宣传标语
  • 税务筹划收费标准最新
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设