位置: 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的发票长啥样
  • 电子税务局发票验旧怎么操作
  • 发票章没盖在盖章处
  • 企业辅助生产车间
  • 免税即征即退先征后退
  • 小企业净资产收益率
  • 应纳税所得额计算公式excel
  • 外资企业所得税和内资区别
  • 电话费发票可以重新开吗
  • 税收缴款书怎么做凭证
  • 营改增前的工程款现在怎么开票
  • 增值税电子发票有限额吗
  • 离职补偿金怎么计算
  • 净资产收益率计算公式用期末净资产
  • 个体户经营所得怎么申报
  • 合伙企业分配比例税法规定
  • 现金支票存根会计要签字吗
  • 净利润和毛利润的计算公式
  • 折旧是属于公司成本吗
  • 差旅费中的车票可以抵扣进项税吗
  • 进口货物完税价格名词解释
  • 单位交水费会计分录
  • 什么是货币资产负债表
  • Laravel Intervention/image图片处理扩展包的安装、使用与可能遇到的坑详解
  • 事业单位需要交企业所得税吗
  • phpstorm ftp
  • 以前年度多计提的附加税怎么冲回
  • php bcmath off
  • 如何进行抵债资金管理
  • 花卉绿萝的养殖方法
  • 临时工的工资需要缴纳工会经费吗
  • 税务机关义务包括
  • 卡洛里山脉
  • chrome浏览器快捷方式
  • 电赛例题
  • 售后租回交易的资产销售价低于市场价承租人作为
  • 资产减值损失为什么要调增
  • 存量资金上缴财政款 预算会计
  • 基本生产成本和辅助生产成本区别
  • python中series的用法
  • 经营活动现金流量比率
  • 季中转一般纳税人申报了小规模后无法勾选认证
  • 企业附加税的税率
  • 微信支付宝等改观了人们的生活方式修改病句
  • 社保滞纳金所得税
  • 小规模纳税人免增值税的政策
  • 金税四期注意什么
  • 购车买的保险分别是什么
  • 出口退税申报系统自检数据撤销
  • 印花税减免额不能为零怎么填
  • 应收利息审计底稿怎么做
  • 所有者权益变动表图片
  • 销项税红字发票如何做账
  • 总账设置包括哪些内容
  • sql中去掉结果为零的
  • sql合并多行到一列
  • centos7怎么配置yum源
  • Mysql inner join on的用法实例(必看)
  • 跨服务器访问数据库
  • 科普知识手抄报简单又漂亮
  • 利用系统的公文有哪些
  • win8如何删除登录密码
  • linux pwdx命令
  • linux带桌面
  • 微软 系统设计
  • windows下用CMD调用COM口
  • 可以自己做手写的软件
  • android studio string函数
  • Android AsyncTask简要分析
  • android 点击按钮如果数据库有数据就更新,没有就创建
  • unity3d总结
  • js实现超精简的快捷键
  • js中checked什么意思啊
  • 纳税申报期过了怎么处理
  • 河南省纪检委网站
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设