N
Nuxt15mo ago
Flinty

API Request not being triggered

Hey all. I have the following composable:
export const get = async (endpoint:string, lazy:boolean = true, errorCatch:boolean = true, fullUrl: boolean = false) => {
let config = useRuntimeConfig()
let apiUrl = config.public.apiUrl
let url = `${apiUrl}/${endpoint}`
console.log(url)
let {data:data, pending:pending, refresh:refresh, error:error} = await useLazyFetch(url)
if(error.value != null && errorCatch)
handleErrors(error)
console.log("ERROR", error)
console.log("DATA", data)
return {data, pending, refresh, error};
}
export const get = async (endpoint:string, lazy:boolean = true, errorCatch:boolean = true, fullUrl: boolean = false) => {
let config = useRuntimeConfig()
let apiUrl = config.public.apiUrl
let url = `${apiUrl}/${endpoint}`
console.log(url)
let {data:data, pending:pending, refresh:refresh, error:error} = await useLazyFetch(url)
if(error.value != null && errorCatch)
handleErrors(error)
console.log("ERROR", error)
console.log("DATA", data)
return {data, pending, refresh, error};
}
When I navigate to the route /communities from /, I run the following code on the communities page:
const {
error: communitiesE,
refresh: communitiesR,
data: communitiesF,
pending: initialPending,
} = await get(`community?pageNumber=${data.page}&size=${data.pageSize}`)
data.communities = communitiesF.value.content
data.totalPages = communitiesF.value.totalPages
data.totalElements = communitiesF.value.totalElements
const {
error: communitiesE,
refresh: communitiesR,
data: communitiesF,
pending: initialPending,
} = await get(`community?pageNumber=${data.page}&size=${data.pageSize}`)
data.communities = communitiesF.value.content
data.totalPages = communitiesF.value.totalPages
data.totalElements = communitiesF.value.totalElements
In my script setup element of the page. For whatever reason, a network request is never kicked off, and the console logs from the composable are all null (bar the URL being logged, which works when I paste the URL into the browser) Any ideas?
5 Replies
Flinty
Flinty15mo ago
I'll note that it works fine, should I refresh while on the /communities endpoint
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Flinty
Flinty15mo ago
See I use useLazyFetch in another Nuxt 3 project, with 0 issues. Main difference is it uses client only for a higher level wrapper Would that make a difference?
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
Flinty
Flinty15mo ago
I'll give it a go, thanks for the suggestion
Want results from more Discord servers?
Add your server