Skip to content

Commit 3755d7c

Browse files
committed
fix: implement auto-refresh cleanup in ListView component
1 parent 895bda7 commit 3755d7c

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

adminforth/spa/src/views/ListView.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ import ResourceListTable from '@/components/ResourceListTable.vue';
189189
import { useCoreStore } from '@/stores/core';
190190
import { useFiltersStore } from '@/stores/filters';
191191
import { callAdminForthApi, currentQuery, getIcon, setQuery } from '@/utils';
192-
import { computed, onMounted, ref, watch, nextTick, type Ref } from 'vue';
192+
import { computed, onMounted, onUnmounted, ref, watch, nextTick, type Ref } from 'vue';
193193
import { useRoute } from 'vue-router';
194194
import { showErrorTost } from '@/composables/useFrontendApi'
195195
import { getCustomComponent, initThreeDotsDropdown } from '@/utils';
@@ -387,6 +387,13 @@ class SortQuerySerializer {
387387
388388
let listAutorefresher: any = null;
389389
390+
function clearAutoRefresher() {
391+
if (listAutorefresher) {
392+
clearInterval(listAutorefresher);
393+
listAutorefresher = null;
394+
}
395+
}
396+
390397
async function init() {
391398
392399
await coreStore.fetchResourceFull({
@@ -434,10 +441,7 @@ async function init() {
434441
}
435442
});
436443
437-
if (listAutorefresher) {
438-
clearInterval(listAutorefresher);
439-
listAutorefresher = null;
440-
}
444+
clearAutoRefresher();
441445
if (coreStore.resource!.options?.listRowsAutoRefreshSeconds) {
442446
listAutorefresher = setInterval(async () => {
443447
await adminforth.list.silentRefresh();
@@ -505,6 +509,10 @@ onMounted(async () => {
505509
initInProcess = false;
506510
});
507511
512+
onUnmounted(() => {
513+
clearAutoRefresher();
514+
});
515+
508516
watch([page], async () => {
509517
setQuery({ page: page.value });
510518
});

0 commit comments

Comments
 (0)