created() {
this.initWebSocket();
},destroyed() {
this.websock.close() //离开路由之后断开websocket连接
},methods: {
//初始化weosocket
initWebSocket() {
this.Mysender = this.getRandomCode(8);
const wsuri = ws + "UIMakeLine/" + this.Mysender;
this.websock = new WebSocket(wsuri);
this.websock.onmessage = this.websocketonmessage;
this.websock.onopen = this.websocketonopen;
this.websock.onerror = this.websocketonerror;
this.websock.onclose = this.websocketclose;
},
// 随机产生不重复的数
getRandomCode(length) {
if (length > 0) {
var data = ["0", "1", "2", "3", "4",
vue websockt 的用法
最新推荐文章于 2022-10-17 16:26:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)