Hi ๐๐ผ
const slug = useState('/');
const page = useState(3);
const { data, pending, error } = await useFetch('/api/something', {
query: {
slug,
page,
}
})
Let's say I have the code above. When either slug or page changes, it will trigger a new request.
And what I want to do is, when slug changes, I want to reset page to 1. Then I could think of something like:
const slug = useState('/');
const page = useState(3);
const { data, pending, error } = await useFetch('/api/something', {
query: {
slug,
page,
}
})
watch(slug, () => {
page.value = 1
})
However this page.value = 1 happens after a new request. So, for example, if slug changes to /a, then...
1. request ({ slug: '/a', page: 3}) - canceled
2. request ({ slug: '/a', page: 1})
How can I prevent this? I couldn't find a way to change page before another request, without changing too much code here.
Thank you for reading!