강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

소나무님의 프로필 이미지
소나무

작성한 질문수

Vue.js 끝장내기 - 실무에 필요한 모든 것

회원 가입 API 호출과 주의 사항

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

작성

·

240

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로 했던 것 같아요. 만약 제가 수업 진행상 에러 처리를 안했더라도 에러 케이스는 항상 처리해 주셔야 합니다 :)

소나무님의 프로필 이미지
소나무
질문자

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

소나무님의 프로필 이미지
소나무

작성한 질문수

질문하기