• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

API 호출 할 때, then ~ catch를 사용하지 않은 이유가 궁금합니다.

22.04.30 15:27 작성 조회수 142

1

완벽가이드에서는 API 호출할 때,
then ~ catch 문을 사용하셨는데

끝장내기에서는
then~catch를 사용하지 않은 이유가 궁금합니다.

 

1. Vue.js 끝장내기 강의에서 API 호출 방법

// api/index.js
import axios from 'axios';

function registerUser(userData) {
    retrun axios.post('http://localhost:3000/signup', userData);
}

export { registerUser };

 

// SignupForm.vue
impor  { registerUser } form '@/api/index';

submitForm() {
    const userData = {
        username: this.username,
        password: this.password,
        nickname: this.nickname,
    };
    registerUser(userData);
}

 

 

2. Vue.js 완변가이드 강의에서 API 호출 방법

// NewsView.vue
create() {          
    axios.get('https://api.hbpwa.co/v0/jobs/1.json')     
        .then( response => {
            this.users = response.data
        })
        .catch( error => {
            console.log(error)
        })
}

 

 

 

답변 1

답변을 작성해보세요.

1

안녕하세요 좋은 질문이네요. 아마 완벽가이드 쪽 코드는 프로미스를 써서 then catch를 했던 것 같고, 끝장내기는 async await라 try catch로 했던 것 같아요. 만약 제가 수업 진행상 에러 처리를 안했더라도 에러 케이스는 항상 처리해 주셔야 합니다 :)

소나무님의 프로필

소나무

질문자

2022.04.30

아~~~!!! 이해되었습니다. 감사합니다!!! ^^