1.什么是websocket? websocket是HTML5提供的一种通信协议,基于tcp协议的全双工通信协议 2.Websocket的应用场景 3.短轮询和定时器的区别 轮询会有性能问题(网络性能 多次链接) 保存状态会有问题 websocket报文的格式 双向通信 Server Push websocket基于HTTP协议 多了 Upgrade: websocket Connection: Upgrade 告诉服务器需要使用websocket sec-websocket-key/protocal/version
服务器会回复websocket-accept websocket断线重连(心跳机制)
let url = ip地址; this.webSocket = new WebSocket(url); this.webSocket.onopen = method; this.webSocket.onclose = method; this.webSocket.onmessage = method; //当接收到一个来自服务器的消息时被调用 this.webSocket.onerror = method;
Vuex state存储数据 getter把state中的数据取出来进行操作,类似于vue中的computer mutation更新数据 action更新数据 modules模块化