微信 QQ這樣平凡處于生活中的應用工具離我們距離很近,就想他們在生活中一樣接近
那么我們就來看看年輕的WebSocket
首先要在node中引入
npm install nodejs-websocket --save
之后我們在組件中呼叫即可
data(){
return{
ws:null,
}
},
created () {
this.ws = new WebSocket("ws://localhost:8101/socketServer/customer/null")
//建立鏈接后回呼
this.ws.onopen = (event)=>{
console.log(event);
},
//建立鏈接時報錯的回呼
this.ws.onerror = (event)=>{
console.log(event)
},
//接收到推送資料時的回呼
this.ws.onmessage = (event)=>{
console.log(event);
},
//關閉時回呼
this.ws.onclose = (event)=>{
console.log(event);
},
//用于向服務端發送資料
this.ws.send("傳輸資料")
}
這樣就可以建立一個簡單的鏈接了,當然地址還是需要你的后端給你
有了靈活的時時推送技術,寫出一個自己的微信還是件難事嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/282161.html
標籤:區塊鏈
