当前位置: 首页 > news >正文

南昌网站建设模板网络公司市场营销策划方案

南昌网站建设模板网络公司,市场营销策划方案,动态网站开发的架构,自己怎么1做网站使用原因:用户网络环境较差,之前使用ws总是出现断连重连,导致数据总是不能实时更新,所以更换为sse npm install event-source-polyfill createWebSocket:创建sse连接 getWebSocketMsg:接收sse消息 impo…

使用原因:用户网络环境较差,之前使用ws总是出现断连重连,导致数据总是不能实时更新,所以更换为sse

npm install event-source-polyfill

createWebSocket:创建sse连接 

getWebSocketMsg:接收sse消息

  import { EventSourcePolyfill } from "event-source-polyfill";import { getToken } from '@/utils/auth'class webSocketClass {constructor(name) {this.localUrl = `http`; //直连阿里云正式环境this.globalCallback = null;this.createWebSocket(name);this.readyState = 0;}createWebSocket(url) {var that =this// 建立连接this.eventSource = new EventSourcePolyfill(this.localUrl+ url,{// 设置重连时间heartbeatTimeout: 60 * 60 * 1000,// 添加tokenheaders: {Authorization: `Bearer ${getToken()}`,},});this.eventSource.onopen = (e) => {console.log("已建立SSE连接~");};this.eventSource.onmessage = (e) => {const d = JSON.parse(e.data);console.log("sse已接受到消息:", d);that.getWebSocketMsg(that.globalCallback);};this.eventSource.onerror = (e) => {console.log("SSE连接错误" + e.readyState);if (e.readyState == EventSource.CLOSED) {console.log("SSE连接关闭");} else if (this.eventSource.readyState == EventSource.CONNECTING) {console.log("SSE正在重连");//重新设置tokenthis.eventSource.headers = {Authorization: `Bearer ${getToken()}`,};} else {console.log("error", e);}};}getWebSocketMsg(callback) {console.log("开始接收sse消息~",this.eventSource);this.eventSource.onmessage = (ev) => {callback && callback(ev);};}close(){this.eventSource.close()console.log("SSE关闭" + e.readyState);}
}
export default webSocketClass;

使用方法:

  this.warningSSE = new vueSSEUtil('/sse/warning/'+this.userId);this.warningSSE.getWebSocketMsg((evt) => {const d = JSON.parse(evt.data);d.warnCode = this.code_to_value(d.warnCode);console.log('sse回调数据',d) });

一定要在页面退出关闭sse

this.warningSSE.close()

http://www.yidumall.com/news/90765.html

相关文章:

  • 英国T4学生签证 可以做网站吗营销模式和营销策略
  • wordpress 被黑福州网seo
  • 个人网站上线流程安卓优化大师手机版
  • 广州营销型网站建设网站推广策划方案
  • 网站访问拒绝北京自动seo
  • 大浪网站建设网页设计与网站开发
  • 路由器做网站教程微信引流推广怎么找平台
  • 靠谱网站建设公司怎么选百度seo排名规则
  • 德源网站建设网站统计数据
  • 福建省人民政府新闻我们seo
  • 创建公司网站免费seo二级目录
  • 顺的网站建设效果百度产品
  • 有多少专门做兼职的网站西安网站排名优化培训
  • 个人网站设计介绍文字创建自己的网页
  • 一键制作自己的app软件seo在线短视频发布页运营
  • 苏州市网站建设服务在线生成个人网站app
  • 知名网站建设怎么样google站长工具
  • 网站长图怎么做百度搜索官方网站
  • 最大的地方门户网站源码白云百度seo公司
  • 昌平企业网站建设淘宝代运营1个月多少钱
  • 南部县人民医院招聘石家庄百度快照优化排名
  • 厦门外贸网站建设 之家今日头条最新消息
  • 西安建网站公司淘宝店铺怎么推广
  • 临沂网站开发多少钱信阳seo优化
  • 网络维护员每天要干哪些事北京seo外包公司要靠谱的
  • 古玩网站建设意义成功的营销案例及分析
  • 石景山做网站东莞网站建设哪家公司好
  • 中国城市建设网网站seo网站
  • 作图神器百度seo网站优化
  • 西安政府网站建设公司seo的内容怎么优化