use async/await

This commit is contained in:
Valery Sinevich 2024-01-30 17:46:51 +03:00
parent be07940021
commit a61a14ad92
3 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useSharedAsyncData } from '../composables/asyncDataTests' import { useSharedAsyncData } from '../composables/asyncDataTests'
const { data, pending } = useSharedAsyncData() const { data, pending } = await useSharedAsyncData()
</script> </script>
<template> <template>

View File

@ -6,10 +6,10 @@ export const useSleep = () => useAsyncData('sleep', async () => {
export const useCounter = () => useFetch('/api/useAsyncData/count') export const useCounter = () => useFetch('/api/useAsyncData/count')
export const useSharedAsyncData = () => { export const useSharedAsyncData = async () => {
const route = useRoute() const route = useRoute()
const { data, execute, pending } = useAsyncData( const { data, execute, pending } = await useAsyncData(
'sharedAsyncData', 'sharedAsyncData',
() => Promise.resolve('some data'), () => Promise.resolve('some data'),
{ {

View File

@ -2,7 +2,7 @@
import { useSharedAsyncData } from '../../composables/asyncDataTests' import { useSharedAsyncData } from '../../composables/asyncDataTests'
import ComponentWithSharedUseAsyncData from '../../components/ComponentWithSharedUseAsyncData.vue' import ComponentWithSharedUseAsyncData from '../../components/ComponentWithSharedUseAsyncData.vue'
const { data, pending, execute } = useSharedAsyncData() const { data, pending, execute } = await useSharedAsyncData()
const router = useRouter() const router = useRouter()
const page = ref(1) const page = ref(1)