Browse Source

调整vue 返回数据的获取方式

master
453530270@qq.com 3 years ago
parent
commit
0f65157779
  1. 53
      src/views/HomeView.vue

53
src/views/HomeView.vue

@ -174,10 +174,10 @@ export default {
reconntime:0, reconntime:0,
} }
}, },
created() { // created() {
// ws // // ws
// this.getsckdata();
}, // },
mounted() { mounted() {
// //
this.btgetdata(this.klselt) this.btgetdata(this.klselt)
@ -186,12 +186,8 @@ export default {
// //
this.getStat(); this.getStat();
// //
this.getInfoDatas() // get data in webscoket
// websocket this.getsckdata();
setInterval(()=>{
this.getsckdata();
},5000)
}, },
// //
@ -679,43 +675,38 @@ export default {
// interface // interface
homeApi.allGcgNumDatas().then(res=>{ homeApi.allGcgNumDatas().then(res=>{
this.ssjgNumDatas = res.data.returnData this.ssjgNumDatas = res.data.returnData
//
}) })
}, },
// //
getsckdata(){ TPgetsckdata_tcp(){
// websocket // websocket
const param ={ const param ={
type:'realTimeData', type:'realTimeData',
} }
const ws = new WebSocket("ws://10.97.121.2/ws"); const ws = new WebSocket("ws://10.97.121.2/ws");
ws.onopen = function() { ws.onopen = function() {
ws.send(JSON.stringify(param)) ws.send(JSON.stringify(param))
}; };
ws.onmessage = function(e) { ws.onmessage = (e)=>{
var jstr = JSON.parse(e.data) var jstr = JSON.parse(e.data)
func1(jstr)
};
//
ws.onclose=function(e){
}
let func2=function(jstr){
const darr = jstr.data; const darr = jstr.data;
this.ssjgNumDatas = darr.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
};
},

Loading…
Cancel
Save