You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With useFetch we have the ability to prevent the request from firing immediately.
This behavior was described in #449 but PR #499 finally doesn't include it.
However, for many use case we need to lazy the instance execution, while we need to access to other data from useAxios in template.
Considering this two following case :
users/index.vue
<template>
<div v-if="isLoading">loading...</div>
<div v-if="isFinished">
<div v-for="user in users" :key="user.id">...</div>
<button @click="increment">Next page</button>
<button @click="dec">Previous page</button>
</div>
</template>
<script lang="ts" setup>
import Users from '~/api/users'
import { get } from 'lodash'
const { execute, headers, isFinished, isLoading, data: users } = Users.index()
// Here, we don't know the last page number until we execute the request and get it on headers
const { count: page, inc, dec } = useCounter(1, { min: 0 })
const perPage = 20
const lastPage = ref(1)
const increment = () => {
if (page.value < lastPage.value) {
inc()
}
}
whenever(headers, (h) => {
lastPage.value = parseInt(get(h, 'x-pagination-total-pages', 1), 10)
})
watchEffect(() => {
execute({ params: { page: page.value, perPage } })
}, { immediate: true })
</script>
In addition, I suggest to directly returns headers and maybe add another option in UseAxiosOptions in order to auto-convert data like axios-case-converter do (to discuss...)
First I suggest to introduce a UseAxiosOptions type optional parameter :
In addition, I suggest to directly returns headers and maybe add another option in UseAxiosOptions in order to auto-convert data like axios-case-converter do (to discuss...)
But I think this topic can be handled in a separate issue if needed
With
useFetch
we have the ability to prevent the request from firing immediately.This behavior was described in #449 but PR #499 finally doesn't include it.
However, for many use case we need to lazy the instance execution, while we need to access to other data from useAxios in template.
Considering this two following case :
In addition, I suggest to directly returns
headers
and maybe add another option inUseAxiosOptions
in order to auto-convert data like axios-case-converter do (to discuss...)First I suggest to introduce a
UseAxiosOptions
type optional parameter :The text was updated successfully, but these errors were encountered: