[NUXT] loading component

2023. 2. 16. 21:42·Language/NUXT
반응형

페이지를 불러오거나 서버 요청을 보낼 때 대기 시간이 발생한다. 이 때 화면이 정지해있으면 사용자는 페이지가 정지한 것인지 동작중인지 알 수 없다. 로딩 페이지를 표시해 작업이 진행중이라는 것을 표시해줘야한다.

NUXT에서는 간단하게 로딩창을 만들 수 있다. 먼저 로딩을 표시하기 위한 컴포넌트를 작성한다.

// @/components/loading.vue
<template>
  <div v-if="loading">
    <div class="text-white">
      Loading...
    </div>
  </div>
</template>
// @/components/loading.vue
<script>
export default {
  name: "loading",
  data: () => ({
    loading: false
  }),
  methods: {
    start() {
      this.loading = true
    },
    finish() {
      this.loading = false
    }
  }
}
</script>

nuxt.config.js을 열고 loading 속성에 작성했던 loading.vue 컴포넌트를 추가한다.

// nuxt.config.js

export default {
    // ...

    loading: '@/components/loading.vue'
}

필요한 부분에서 $nuxt.$loading 을 사용하면 된다.

async clickLogin() {
    this.$nuxt.$loading.start()
    await this.login()
    this.$nuxt.$loading.finish()
},
반응형
저작자표시 비영리 변경금지 (새창열림)
'Language/NUXT' 카테고리의 다른 글
  • [NUXT3] 500 window is not defined
덴마크초코우유
덴마크초코우유
IT, 알고리즘, 프로그래밍 언어, 자료구조 등 정리
    반응형
  • 덴마크초코우유
    이것저것끄적
    덴마크초코우유
  • 전체
    오늘
    어제
    • 분류 전체보기 (124)
      • Spring Framework (10)
        • Spring (5)
        • JPA (3)
        • Spring Security (0)
      • Language (51)
        • Java (11)
        • Python (10)
        • JavaScript (5)
        • NUXT (2)
        • C C++ (15)
        • PHP (8)
      • DB (16)
        • MySQL (10)
        • Reids (3)
        • Memcached (2)
      • 개발 (3)
      • 프로젝트 (2)
      • Book (2)
      • PS (15)
        • 기타 (2)
        • 백준 (2)
        • 프로그래머스 (10)
      • 딥러닝 (8)
        • CUDA (0)
        • Pytorch (0)
        • 모델 (0)
        • 컴퓨터 비전 (4)
        • OpenCV (1)
      • 기타 (16)
        • 디자인패턴 (2)
        • UnrealEngine (8)
        • ubuntu (1)
        • node.js (1)
        • 블로그 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    FPS
    딥러닝
    select
    mscoco
    블루프린트
    Unreal Engine
    pytorch
    Python
    파이썬
    웹
    C++
    알고리즘
    게임 개발
    PS
    프로그래머스
    C
    JS
    php
    자바
    NUXT
    JavaScript
    redis
    MySQL
    언리얼엔진4
    CPP
    map
    memcached
    Unreal
    게임
    클래스
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
덴마크초코우유
[NUXT] loading component
상단으로

티스토리툴바