Skip to content

Commit 5618b00

Browse files
committed
Restrict refresh when unmounted
1 parent 7be7708 commit 5618b00

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

stores/useModelData.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@ export default defineStore('model-data', () => {
2626
const apiKey = useAppRefKey();
2727

2828
const model = useModel();
29-
const modelId = computed(() => model.target!.id);
29+
const modelId = computed(() => model.target?.id);
3030

3131
const { data, pending, refresh } = useLazyFetch<NormalizedModelData[]>(
3232
() => `/models/${modelId.value}/model-data`,
3333
{
3434
method: 'GET',
3535
query: { apiKey },
3636
server: false,
37+
// So we can manually fetch
38+
watch: false,
3739
}
3840
);
3941

42+
watch(modelId, () => {
43+
if (modelId.value) {
44+
refresh();
45+
}
46+
})
47+
4048
const list = computed(() => data.value || []);
4149
const isDisabled = computed(() => list.value.length === 50 || pending.value);
4250

0 commit comments

Comments
 (0)