From 0f65157779e1220c40055e3688586d431df08725 Mon Sep 17 00:00:00 2001 From: "453530270@qq.com" Date: Fri, 28 Jul 2023 11:59:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4vue=20=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/HomeView.vue | 53 ++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 614a82f..c870ccb 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -174,10 +174,10 @@ export default { reconntime:0, } }, - created() { - // 初始化ws 链接 - - }, + // created() { + // // 初始化ws 链接 + // this.getsckdata(); + // }, mounted() { // 客流趋势 this.btgetdata(this.klselt) @@ -186,12 +186,8 @@ export default { //统计日月年进馆总数 this.getStat(); // - this.getInfoDatas() - // 设置websocket定时 - setInterval(()=>{ - this.getsckdata(); - },5000) - + // get data in webscoket + this.getsckdata(); }, // 方法 @@ -679,43 +675,38 @@ export default { // interface homeApi.allGcgNumDatas().then(res=>{ this.ssjgNumDatas = res.data.returnData - // - }) - - }, - // - getsckdata(){ + // 待删除 + TPgetsckdata_tcp(){ // websocket const param ={ type:'realTimeData', } - const ws = new WebSocket("ws://10.97.121.2/ws"); ws.onopen = function() { ws.send(JSON.stringify(param)) }; - ws.onmessage = function(e) { + ws.onmessage = (e)=>{ var jstr = JSON.parse(e.data) - func1(jstr) - }; - // - ws.onclose=function(e){ - - } - - let func2=function(jstr){ const darr = jstr.data; this.ssjgNumDatas = darr.data - console.log("ws_out") - console.log(this.ssjgNumDatas) - } - - let func1 = func2.bind(this) + }; }, + // udp + getsckdata(){ + // websocket + const ws = new WebSocket("ws://10.97.121.2/rt"); + ws.onopen = function() { + console.log("ws connected success!") + }; + ws.onmessage = (e)=> { + var jstr = JSON.parse(e.data) + this.ssjgNumDatas=jstr.data + }; + },