NuxtN
Nuxt3y ago
9 replies
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};
}


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
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?
Was this page helpful?