비동기
-
Axios 설치 및 사용React 2023. 7. 21. 23:07
동기 vs 비동기 - 비동기 방식은 웹페이지를 리로드하지 않고 데이터를 불러오는 방식 - 만약에 동기면 서버에게 요청을 하고 리턴 받을 때까지 다른 업무를 하지 못 함 - Promise API를 활용하는 HTTP 비동기 통신 라이브러리 Promise는 간단히 말해 비동기 처리를 간단히 해주는 객체 Promise 상태 Pending (대기): 비동기 처리 로직이 아직 미완료 상태 Fulfilled (이행): 비동기 처리가 완료되어 Promise가 결과 값을 반환해준 상태 Rejected (실패): 비동기 처리가 실패하거나 오류가 발생한 상태 설치 npm install axios 파일 경로 src/axios/axios.js import axios from 'axios'; const request = axio..