位置: 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%的税率吗
  • 资本公积转增股本个人所得税
  • 盘盈的固定资产通过待处理财产损益科目核算
  • 居民企业核定征收企业所得税的项目有哪些
  • 资产负债表专项储备放哪个科目?
  • 专票丢失登报后怎么处理
  • 转让折旧怎么算
  • 现金流量表上的期末现金余额等于___
  • 职工旅游费计入什么科目
  • 公对公转账银行拒绝是什么意思
  • 一般纳税人企业所得税政策最新2023税率
  • 企业所得税一般纳税人是怎么缴纳的
  • 增值税发票单位可以不填吗
  • 个体户可以申请公章吗
  • 发票查重
  • 金蝶kis云专业版原材料数量怎么录入
  • 上月开的发票本月作废怎么处理
  • 计算应纳税所得额时可以扣除的项目有
  • 收到负数购入发票怎么办
  • 没有原始凭证可以审计吗
  • 如何利用流产让男人愧疚
  • 一家公司各项费用支出
  • windows怎么复制
  • 农民专业合作社法
  • 公司没有营业额零报税的后果
  • 半月湾在哪
  • 如何防范增值税的税收风险
  • 车辆赔偿款收条怎么写
  • 零售业如何盈利
  • top命令可以看到哪些信息
  • php多图片上传到数据库
  • thinkphp post
  • 消费税会计分录怎么做的
  • 建筑业挂靠工程会计与税务处理怎么做?
  • ghostnet改进
  • dpkg命令详解
  • mysql分表数量取决于什么
  • 公司间代收代付
  • 补税分录
  • 行政性罚款怎么结转损益
  • 帝国cms调用api接口
  • 银行结算方式有哪几种?其具体内容是什么
  • 工厂加工外包
  • 投资性房地产的后续计量
  • 代收电费增值税品目
  • 凭证类别的种类及限制条件
  • 工业销售产值是销售收入吗
  • 白条抵库现象
  • 逾期交房违约金 已支付金额
  • 个体户要怎么注册公司
  • 会计分录什么时候用负数表示
  • 政府奖励企业如何领取
  • 史上最简单的飞镖
  • Win10 Mobile 10549 预览版新功能上手体验视频
  • services.exe修改注册表
  • ubuntu系统如何安装
  • macos越狱教程
  • freebsd软件安装
  • linux www服务器配置
  • 进程lsass.exe
  • win8使用教程和技能
  • win10右下角弹出全屏截图
  • centos 安装
  • gzip与zip
  • win7 u盘启动按哪个键
  • 如何关闭win8自带杀毒
  • shell监控进程
  • css图片垂直居中对齐
  • Vuforia 4.0 beta——Object Recognition (二)
  • 批处理计数
  • unity协程的工作原理
  • Android自定义动画
  • 广西12366医保缴费
  • 资产管理公司收购不良资产后怎么处置
  • 浙江国地税联合税务局
  • 河南电子税务局电话
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设