From 5208eca0fa637a65bd10230c394060b1b38ffdee Mon Sep 17 00:00:00 2001 From: edgexie <18474752+edgexie@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:02:42 +0800 Subject: [PATCH] fix: mqtt client.end error in onUnmounted, update some style --- src/views/able/mqtt-client.vue | 71 +++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/src/views/able/mqtt-client.vue b/src/views/able/mqtt-client.vue index 9271e6535..4a880204c 100644 --- a/src/views/able/mqtt-client.vue +++ b/src/views/able/mqtt-client.vue @@ -25,19 +25,20 @@ const connection = reactive({ // 订阅 topic/mqttx 主题 const subscription = ref({ topic: "topic/mqttx", - qos: 0 as mqtt.QoS + qos: 0 as any }); // 发布 topic/browser 主题 const publish = ref({ topic: "topic/browser", - qos: 0 as mqtt.QoS, + qos: 0 as any, payload: '{ "msg": "Hello, I am browser." }' }); let client = ref({ connected: false } as mqtt.MqttClient); + const receivedMessages = ref(""); const subscribedSuccess = ref(false); const btnLoadingType = ref(""); @@ -175,37 +176,37 @@ const handleProtocolChange = (value: string) => { }; onUnmounted(() => { - client.value.end(); + try { + if (client.value.end) { + client.value.end(); + console.log("disconnected successfully"); + } + } catch (error) { + console.log(error); + } });