refactor(client): extract interval logic to a composable function
あと`onUnmounted`を`onMounted`内で呼んでいたりしたのを修正したりとか
This commit is contained in:
parent
6a4574b612
commit
5e95a1f7af
18 changed files with 207 additions and 183 deletions
|
|
@ -8,9 +8,10 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { GetFormResultType } from '@/scripts/form';
|
||||
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
||||
import { GetFormResultType } from '@/scripts/form';
|
||||
import * as os from '@/os';
|
||||
import { useInterval } from '@/scripts/use-interval';
|
||||
|
||||
const name = 'onlineUsers';
|
||||
|
||||
|
|
@ -43,12 +44,9 @@ const tick = () => {
|
|||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
tick();
|
||||
const intervalId = window.setInterval(tick, 1000 * 15);
|
||||
onUnmounted(() => {
|
||||
window.clearInterval(intervalId);
|
||||
});
|
||||
useInterval(tick, 1000 * 15, {
|
||||
immediate: true,
|
||||
afterMounted: true,
|
||||
});
|
||||
|
||||
defineExpose<WidgetComponentExpose>({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue