Composables

useLazySanctumFetch

How to use useLazySanctumFetch to fetch data from Laravel API

Usage

This composable uses Nuxt's native createUseFetch factory internally, providing full parity with Nuxt's built-in useLazyFetch.

For complete usage details, options, and return types, see the official Nuxt documentation.

Note: lazy: true is set internally.

const { data, status, error, refresh, clear } = await useLazySanctumFetch("/api/users")

// with options
const { data } = await useLazySanctumFetch("/api/users", {
  method: "GET",
  query: { page: 1 },
})

You can also use type casting to work with the response as an interface:

interface MyResponse {
  name: string
}

const { data } = await useLazySanctumFetch<MyResponse>("/api/endpoint")
const name = data.value?.name