From 37b00d8d17fc12f393d5b9ee34fc1451d6ee8111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B4=9B=E5=B8=8C=E9=9B=85?= Date: Wed, 8 May 2024 13:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=9B=B4=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E7=9A=84=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mqtt/index.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/views/mqtt/index.vue b/src/views/mqtt/index.vue index 4d0892c..b616cc1 100644 --- a/src/views/mqtt/index.vue +++ b/src/views/mqtt/index.vue @@ -88,7 +88,12 @@ async function publish() { } publishing.startTime = Date.now() publishing.count = list.length - while (!exit) { + // 发送数据的定时器 + const interval = setInterval(() => { + if (exit) { + clearInterval(interval) + return + } const item = next() publishing.lastTime = Date.now() if (item[0]?.content[0]) { @@ -103,9 +108,7 @@ async function publish() { const json = JSON.stringify(item) mqttClient!.publish(topic, json, {}) - - await delay(100) - } + }, 100) })().catch((e) => console.error(e)) }