I am trying to dynamically retrieve the total number of pages from my API response header, which includes "x-total-count = 50". However, I am struggling to figure out how to access this variable in my frontend. Here is a snippet of my code:
const sort = ref({ column: 'licensePlate', direction: 'asc' as const })
const page = ref(1)
const pageCount = ref(10)
const pageTotal = ref(50) //This value should be dynamic coming from the API
const pageFrom = computed(() => (page.value - 1) * pageCount.value + 1)
const pageTo = computed(() => Math.min(page.value * pageCount.value, pageTotal.value))
// Data
const { data: cars, status} = await useLazyAsyncData<{
licensePlate: string
arrivalDate: string
charge: number
}[]>('cars', (response) => ($fetch as any)(`http://localhost:3001/deported`, {
query: {
q: search.value,
'_page': page.value,
'_limit': pageCount.value,
'_sort': sort.value.column,
'_order': sort.value.direction
}
}), {
default: () => [],
watch: [page, search, pageCount, sort]
})
I have not been successful in attempting any solutions so far.