Nuxt/test/fixtures/basic/composables/asyncDataTests.ts

28 lines
561 B
TypeScript
Raw Normal View History

export const useSleep = () => useAsyncData('sleep', async () => {
await new Promise(resolve => setTimeout(resolve, 50))
return 'Slept!'
})
export const useCounter = () => useFetch('/api/useAsyncData/count')
2023-10-27 22:21:20 +00:00
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
}
}