I'm trying to use either pending
or status
with the useFetch composable in Nuxt 3 to disable a button and show a spinner when a POST request is pending like so:
const { pending, status, execute } = await useFetch("/notifyme", {
immediate: false,
baseURL: config.public.apiBase,
method: "POST",
body: {
email: email.value,
},
});
When using pending
as below, the button is disabled and spinner is showing by default even before the request has been made:
<button
:disabled="pending"
type="submit">
Notify me
<ButtonSpinner v-show="pending" />
</button>
When using status
as below, the button is not disabled and spinner is not showing by when the request is made:
<button
:disabled="status==='pending'"
type="submit">
Notify me
<ButtonSpinner v-show="status==='pending'" />
</button>
I'm confused as to how to use pending
and status
for useFetch and why both of them exist if they are so similar.