From 9fd683529ddcc3a843f639a05051fdd6ef56e378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Tue, 12 Sep 2023 18:29:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20`websocket`=20=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B6=88=E6=81=AF=E6=8E=A5=E6=94=B6=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: ed7644956d9d99b8565beec5aeae21a02f52bf12 --- src/views/demo/websocket.vue | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/views/demo/websocket.vue b/src/views/demo/websocket.vue index 539db1af..0d1ba270 100644 --- a/src/views/demo/websocket.vue +++ b/src/views/demo/websocket.vue @@ -4,6 +4,10 @@ import SockJS from "sockjs-client"; import Stomp from "stompjs"; +import { useUserStoreHook } from "@/store/modules/user"; + +const userStore = useUserStoreHook(); + const inputVal = ref("初始内容"); const topicMsgs = ref(["接收到一条主题消息"]); // 主题消息列表 @@ -14,7 +18,7 @@ function handleSendToAll() { } function handleSendToUser() { - stompClient.send("/app/sendToUser", {}, inputVal.value); + stompClient.send("/app/sendToUser/root", {}, inputVal.value); } let stompClient: Stomp.Client; @@ -24,14 +28,14 @@ function initWebSocket() { stompClient = Stomp.over(socket); - stompClient.connect({}, () => { + stompClient.connect({ Authorization: userStore.token }, () => { console.log("连接就绪,订阅主题:", "/topic/all"); - stompClient.subscribe("/topic/all", (res) => { + stompClient.subscribe("/topic/notice", (res) => { console.log("广播消息接收", res); }); - stompClient.subscribe("/user/queue/reply", (res) => { + stompClient.subscribe("/user/queue/greeting", (res) => { console.log("点对点消息接收", res); }); });