<template>
<div>
{{ pending ? 'Loading' : count }}
</div>
</template>
<script setup>
//Navigation will occur before fetching is complete. Handle pending and error states directly within your component's template
const { pending, data: count } = useLazyAsyncData('count', () => $fetch('/api/count'))
watch(count, (newCount) => {
// Because count starts out null, you won't have access
// to its contents immediately, but you can watch it.
})
</script>
// Using Async Setup
<script>
export default defineComponent({
async setup() {
const [{ data: organization }, { data: repos }] = await Promise.all([
useFetch(`https://api.github.com/orgs/nuxt`),
useFetch(`https://api.github.com/orgs/nuxt/repos`)
])
return {
organization,
repos
}
}
})
</script>
<template>
<header>
<h1>{{ organization.login }}</h1>
<p>{{ organization.description }}</p>
</header>
</template>
REF>
문제 : API 를 넣는 와중에 tab 기능이 안됨
원인 : ref로 만들었던 변수를 바꾸려고 할때 변수는 바뀌는데 이게 reactive가 잘 안되었다.
해결 : reactive()를 사용해서 바꾸니 기능은 작동한다.
⇒ ref 와 reactive에 대해서 정확하게 다시 정리해봐야겠다.