From 5e03afec0ada267b28219dfa8c25bb51c8566782 Mon Sep 17 00:00:00 2001 From: "Alisa | Side.one" Date: Fri, 9 Jun 2023 20:19:57 +0800 Subject: [PATCH] feat: The timer is cleared uniformly --- src/modules/[chain]/consensus/index.vue | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/[chain]/consensus/index.vue b/src/modules/[chain]/consensus/index.vue index 6e55dbb0..970871b2 100644 --- a/src/modules/[chain]/consensus/index.vue +++ b/src/modules/[chain]/consensus/index.vue @@ -20,7 +20,7 @@ let rate = ref(''); let height = ref(''); let round = ref(''); let step = ref(''); -let timer = null; +let timer = null as any; let updatetime = ref(new Date()); let positions = ref([]); let validatorsData = ref([] as any); @@ -30,14 +30,19 @@ onMounted(async () => { rpc.value = rpcList.value[0].address + '/consensus_state'; fetchPosition(); update(); + clearTime() timer = setInterval(() => { update(); }, 6000); }); onUnmounted(() => { - timer = null; + clearTime(); }); +function clearTime() { + clearInterval(timer); + timer = null; +} const newTime = computed(() => { return format.toDay(updatetime.value, 'time'); }); @@ -79,7 +84,7 @@ function onChange() { httpstatus.value = 200; httpStatusText.value = ''; roundState.value = {}; - timer = null; + clearTime(); fetchPosition(); update(); timer = setInterval(() => {