[TIL] 221208

EllaDev·2022년 12월 8일
0

Today I Learn

목록 보기
2/13

Demo API

useLazyAsyncData

  • 페이지 렌더링 전에 초기 데이터를 가져오기 위해서 사용
    <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>
  • useLazyAsyncData와 useAsyncData의 차이는??

REF>

useLazyAsyncData

Data Fetching

배포

  • SSR 배포 및 SSG 배포의 차이??
  • 클라이언트 배포는 어떻게??

Tab

이슈

문제 : API 를 넣는 와중에 tab 기능이 안됨

원인 : ref로 만들었던 변수를 바꾸려고 할때 변수는 바뀌는데 이게 reactive가 잘 안되었다.

해결 : reactive()를 사용해서 바꾸니 기능은 작동한다.

⇒ ref 와 reactive에 대해서 정확하게 다시 정리해봐야겠다.

profile
Frontend Developer

0개의 댓글