小编pre*_*ron的帖子

弹簧stolds websockets与vue.js

我正在尝试使用带有Vue的Spring websockets(STOMP),但无法弄清楚如何做到这一点,或者它是否可能.我的websockets使用普通的JS,但当我尝试使用Vue时,我会卡住.这是我的vue代码:

var app = new Vue({
el: '#app',
data: {
    stompClient: null,
    gold: 0
},
methods: {
    sendEvent: function () {
        this.stompClient.send("/app/hello", {}, JSON.stringify({'name': $("#name").val()}));
    }
},
created: function () {
    this.stompClient = Stomp.over(new SockJS('/gs-guide-websocket'));
    this.stompClient.connect()
    this.stompClient.subscribe('/topic/greetings', function (greeting) {
        console.log(JSON.parse(greeting.body).content);
    });
},
Run Code Online (Sandbox Code Playgroud)

})

我的连接和发送功能正在工作,我可以看到后端的消息,但问题是订阅功能.它需要一个回调函数,但这永远不会触发.我也尝试在vue中创建一个方法并调用它

this.stompClient.subscribe('/topic/greetings', vueFunc())
Run Code Online (Sandbox Code Playgroud)

但这也不起作用.我在https://github.com/FlySkyBear/vue-stomp找到了一些库,但我无法弄清楚如何使用它,它看起来非常混乱.我宁愿使用普通的JS.

有人有解决方案吗?谢谢

javascript spring stomp spring-websocket vuejs2

6
推荐指数
1
解决办法
5820
查看次数

无法在map函数内捕获异常

我正在尝试捕获由传递给map函数的函数引发的异常,但未捕获。我不明白为什么。

例:

(defn x [x]
  (throw (Exception. "An exception")))

(try
  (map x '(1 2 3))
  (catch Exception e "caught exception"))
Run Code Online (Sandbox Code Playgroud)

exception-handling exception function clojure

3
推荐指数
1
解决办法
649
查看次数