vue如何再頁(yè)面渲染websocket請(qǐng)求得到的數(shù)據(jù)data(){return:{marketTrades:[],}},mounted(){this.someThing();},methods:{someThing(){constwebsocketId=String(this.optionValue);constws=newWebSocket("ws://192.168.8.8888:8888/message");ws.onopen=function(){??const?from={"req":"sub","channel":"market.all","market":websocketId}??ws.send(JSON.stringify(from));};ws.onmessage=function(evt){?constresult=evt.data;?constdata=JSON.parse(event.data)?this.marketTrades=data.data['market.trades'];//實(shí)時(shí)成交數(shù)據(jù)?console.log(this.marketTrades);//實(shí)時(shí)成交數(shù)據(jù),這里能正確返回需要的數(shù)據(jù)};}}在websocket里面能正確打印出‘實(shí)時(shí)成交數(shù)據(jù)’,但是要把數(shù)據(jù)渲染到界面中的時(shí)候,這個(gè)this.marketTrades是空。我在網(wǎng)上查過(guò),說(shuō)是數(shù)據(jù)的作用域不同,但是還是找不到解決方法請(qǐng)問(wèn)下這種應(yīng)該怎么去正確渲染呢
在線等,挺急的!vue如何渲染websocket數(shù)據(jù)跪求!
翻閱古今
2019-06-21 17:06:18