refactor(client): extract interval logic to a composable function

あと`onUnmounted`を`onMounted`内で呼んでいたりしたのを修正したりとか
This commit is contained in:
syuilo
2022-06-26 03:12:58 +09:00
parent 6a4574b612
commit 5e95a1f7af
18 changed files with 207 additions and 183 deletions

View File

@ -18,6 +18,7 @@
import { onMounted, onUnmounted, ref } from 'vue';
import MkMiniChart from '@/components/mini-chart.vue';
import * as os from '@/os';
import { useInterval } from '@/scripts/use-interval';
const instances = ref([]);
const charts = ref([]);
@ -34,15 +35,9 @@ const fetch = async () => {
fetching.value = false;
};
let intervalId;
onMounted(() => {
fetch();
intervalId = window.setInterval(fetch, 1000 * 60);
});
onUnmounted(() => {
window.clearInterval(intervalId);
useInterval(fetch, 1000 * 60, {
immediate: true,
afterMounted: true,
});
</script>