How to implement abortController #300
-
Today I noticed the performance in our application could be improved by cancelling requests when navigating away from the page. I tried to implement Am I doing something wrong? 😄 any help is greatly appreciated! <script setup lang="ts">
const client = useSanctumClient();
const abortController = new AbortController();
onUnmounted(() => abortController.abort());
const { data } = await useAsyncData(() =>
client('/example-endpoint', {
signal: abortController.signal
})
);
</script> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @martijnhalekor, good question! Your example looks good to me, I also checked the sources of My wild guess is to make sure that your If nothing helps and you can't find a solution, let me know and I will convert it to the issue to find a solution. |
Beta Was this translation helpful? Give feedback.
I am happy to share I got it working by switching to
onBeforeRouteLeave
. This does raise the question when or why we needonUnmounted
hook? 🤔 I still use that hook in a few components to remove keyboard event listeners. Perhaps I should consider moving these to thebeforeUnmount
hook to make sure they are actually removed as it seems I shouldn't trust my current method.