mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 11:27:13 +00:00
28 lines
561 B
TypeScript
28 lines
561 B
TypeScript
export const useSleep = () => useAsyncData('sleep', async () => {
|
|
await new Promise(resolve => setTimeout(resolve, 50))
|
|
|
|
return 'Slept!'
|
|
})
|
|
|
|
export const useCounter = () => useFetch('/api/useAsyncData/count')
|
|
|
|
export const useSharedAsyncData = () => {
|
|
const route = useRoute()
|
|
|
|
const { data, execute, pending } = useAsyncData(
|
|
'sharedAsyncData',
|
|
() => Promise.resolve('some data'),
|
|
{
|
|
default: () => 'default data',
|
|
immediate: false,
|
|
watch: [() => route.query]
|
|
}
|
|
)
|
|
|
|
return {
|
|
data,
|
|
execute,
|
|
pending
|
|
}
|
|
}
|