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

@@ -29,6 +29,7 @@
import { onUnmounted, watch } from 'vue';
import { v4 as uuid } from 'uuid';
import tinycolor from 'tinycolor2';
import { useInterval } from '@/scripts/use-interval';
const props = defineProps<{
src: number[];
@@ -65,9 +66,8 @@ function draw(): void {
watch(() => props.src, draw, { immediate: true });
// Vueが何故かWatchを発動させない場合があるので
clock = window.setInterval(draw, 1000);
onUnmounted(() => {
window.clearInterval(clock);
useInterval(draw, 1000, {
immediate: false,
afterMounted: true,
});
</script>