-送风 2019-10-07 18:51 采纳率: 50%
浏览 636
已采纳

使用websocket时报错,求教各位大哥

在使用websocket的时候报错


Uncaught TypeError: Cannot read property 'subscribe' of undefined




图片说明




代码很简单

            init() {
                let socket = new SockJS('http://127.0.0.1:8080/gs-guide-websocket');
                this.stompClient = Stomp.over(socket);
                this.stompClient.connect({}, function (frame) {
                    this.stompClient.subscribe('/topic/greetings', function (msg) {
                        console.log(msg.body)
                    });
                });
            },

不知道为啥报错


请教各位大哥,小弟谢过啦

  • 写回答

2条回答 默认 最新

  • 毕小宝 领域专家: 后端开发技术领域 2019-10-08 09:03
    关注

    说明这个 this.stompClient 是 undefined 的,因为前面一步连接 Server 的时候报了 server undefined 了。
    检查下服务器端 websocket 请求类是否正确。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?