Computes an asynchronous value, updating the reference when the effect resolves.
The type of the computed value.
The asynchronous effect that computes the value.
A reactive reference that contains the computed value or undefined until the effect resolves.
const data = useAsyncComputed<{ downloads: number; end: string; package: string; start: string }>((onCancel) => {
const controller = new AbortController()
onCancel(() => controller.abort())
const url = new URL('https://api.npmjs.org/downloads/point/last-week/vue')
const request = new Request(url, { signal: controller.signal })
return fetch(request).then((response) => response.json())
})
Computes an asynchronous value, updating the reference when the effect resolves.
The type of the computed value.
The asynchronous effect that computes the value.
A function that returns an initial value for the computed value.
Optionaloptions: UseAsyncComputedOptionsOptional configuration options.
A reactive reference that contains the computed value or the initial value until the effect resolves.
const data = useAsyncComputed<{ downloads: number; end: string; package: string; start: string } | null>(
(onCancel) => {
const controller = new AbortController()
onCancel(() => controller.abort())
const url = new URL('https://api.npmjs.org/downloads/point/last-week/vue')
const request = new Request(url, { signal: controller.signal })
return fetch(request).then((response) => response.json())
},
() => null,
)
Computes an asynchronous value, updating the reference when the effect resolves.
Example
Template: T
The type of the computed value.
Param: effect
The asynchronous effect that computes the value.
Param: init
Optional function that returns an initial value for the computed value.
Param: options
Optional configuration options.
Returns
A reactive reference that contains the computed value or
undefinedif not initialised.