vue做websocket,后台用的是stomp

在export default 外面 var stompClient = null;

methods

connection() {
            // 建立连接对象
            this.socket = new SockJS('http://192.168.6.56:8081/endpoint'); 
            stompClient = Stomp.over(this.socket);
            //广播(一对多)
            stompClient.connect({}, (frame) => {
                console.log('Connected:' + frame);
                在这里调一对多的接口就可以('/topic/getResponse'),调一对多的接口就不行('/user/39/queue/getResponse')
                stompClient.subscribe('/user/39/queue/getResponse',function(response){
                    console.log(123123123)
                    console.log(JSON.parse(response.body));
                })
            }, (err) => {
                console.log(err)
            });

        },

mounted

this.connection()
阅读 1.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题