feat: The timer is cleared uniformly

This commit is contained in:
Alisa | Side.one 2023-06-09 20:19:57 +08:00
parent b1f5684638
commit 5e03afec0a

View File

@ -20,7 +20,7 @@ let rate = ref('');
let height = ref(''); let height = ref('');
let round = ref(''); let round = ref('');
let step = ref(''); let step = ref('');
let timer = null; let timer = null as any;
let updatetime = ref(new Date()); let updatetime = ref(new Date());
let positions = ref([]); let positions = ref([]);
let validatorsData = ref([] as any); let validatorsData = ref([] as any);
@ -30,14 +30,19 @@ onMounted(async () => {
rpc.value = rpcList.value[0].address + '/consensus_state'; rpc.value = rpcList.value[0].address + '/consensus_state';
fetchPosition(); fetchPosition();
update(); update();
clearTime()
timer = setInterval(() => { timer = setInterval(() => {
update(); update();
}, 6000); }, 6000);
}); });
onUnmounted(() => { onUnmounted(() => {
timer = null; clearTime();
}); });
function clearTime() {
clearInterval(timer);
timer = null;
}
const newTime = computed(() => { const newTime = computed(() => {
return format.toDay(updatetime.value, 'time'); return format.toDay(updatetime.value, 'time');
}); });
@ -79,7 +84,7 @@ function onChange() {
httpstatus.value = 200; httpstatus.value = 200;
httpStatusText.value = ''; httpStatusText.value = '';
roundState.value = {}; roundState.value = {};
timer = null; clearTime();
fetchPosition(); fetchPosition();
update(); update();
timer = setInterval(() => { timer = setInterval(() => {