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

  • 增值税一般纳税人证明文件
  • 增值税一般纳税人税率
  • 月末处理工作主要包括
  • 其他应收款属于应收账款吗
  • 小规模纳税人建筑工程增值税税率
  • 出口未开票怎么会计处理
  • 一般纳税人印花税是季报还是月报
  • 事业单位存货发生盘亏或盘盈处理
  • 个体户电子发票怎么作废
  • 发放代扣代缴个人所得税分录
  • 分给当期投资者利润如何做会计分录?
  • 制造费用属于哪一类科目
  • 以旧换新如何确认收入
  • 借款合同法律规定的表述
  • 销售亏损原因分析范文
  • 购进固定资产汽车该如何进行会计处理?
  • 个人交年金的多少有什么区别
  • 代持股 税收
  • 低价销售代替非正常损失避免转出进项税?
  • 甲公司聘用乙为业务经理
  • 跨年度多计提的租金怎么冲
  • 专项资金如何做账务处理
  • 应收股利的账务处理方法
  • 企业分立账务处理办法
  • 1697511073
  • 合并财务报表中的负债和股东权益
  • 服务器centos6.9安装教程
  • 外币报表折算差额计入其他综合收益
  • 个人所得税的征收模式为()A分类征收B综合征收C
  • 导航菜单是什么
  • 增值税多交可以退税吗
  • php 文件系统
  • php调试函数
  • gridview怎么连接数据库
  • vue调用高德js
  • 如何设置长期有效的群二维码安卓手机
  • vue实现文件上传和下载
  • php开发接口
  • 税控盘减免税款结转会计分录
  • 收残疾人就业保险合法吗
  • asp和asp net
  • 其他科技推广服务业可以加计扣除吗
  • 商业承兑汇票的流程
  • 交易性金融资产入账价值怎么计算
  • 文化事业建设税是含税还是不含税
  • 建筑企业结转成本附件
  • 高新技术企业补助需要交所得税吗
  • 企业第四季度是什么时候
  • 燃油费如何做账会计分录
  • 公允价值变动损益和投资收益区别
  • 企业收到政府补助金80 000元,存入银行
  • 收到客户不要的定金怎么做账?
  • 资本金与注册资本的关系
  • 如何创建桌面快捷方式电脑
  • win2003安全模式怎么进
  • mac怎么打开mac系统
  • 苹果mac怎么复制文字
  • win10阻止可能不需要的应用吗
  • rundll32exe应用程序错误
  • centos7 ip命令
  • 电脑出现nobootdevicefound咋办
  • 第三方解决方案
  • 前端node跨域处理
  • unity游戏之羊刀与Pendragon复盘:DotA做对了什么
  • 计算机入域怎么操作
  • css怎么更换图片
  • python爬取某人所有朋友圈
  • Unity WWW网络动态加载和储存在本地
  • python 中 range
  • js 在线调试
  • node.js 环境配置
  • 给shell脚本传参数
  • 理解Python中的变量
  • 分享面试流程
  • android中使用sharedprefence的步骤
  • 深圳买新房契税怎么收
  • 江苏电子税务局网站官网
  • 个人所得税完税证明图片
  • 计算本月应交消费税分录
  • 津补贴怎么算
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设