A, install,
npm install sockjs-client --save
Copy the code
Second, the use of
import SockJS from 'sockjs-client'; mounted(){ this.connection(); }, methods: {// establish connection(){let orderId = '200665765656567757656754'; Establish a connection object / / / / connected to the server to provide communication interface. This socket = new SockJS (` http://22.0.157.40:10020/business-h5/orders/ws/status? oid=${orderId}&token=${this.tradeToken}`); let self = this; this.socket.onopen = function (){ console.info('open'); self.socket.send('from client'); }; this.socket.onmessage = function (e) { console.info('message', e.data); }; this.socket.onclose = function (){ console.info('close'); }; this.socket.onerror = function (e){ console.info(e); }; }}Copy the code