[πŸ“š 라이브러리] Axios μ‚¬μš©λ²•

dsfasdΒ·2022λ…„ 11μ›” 11일
0

Axios

Axios μžλ°”μŠ€ν¬λ¦½νŠΈμ—μ„œ μ§€μ›ν•˜λŠ” fetch와 λΉ„μŠ·ν•œ 역할을 ν•˜λŠ” μ¨λ“œνŒŒν‹° λΌμ΄λΈŒλŸ¬λ¦¬μ΄λ‹€.

  • μ¨λ“œνŒŒν‹° 라이브러리둜 λ³„λ„μ˜ μ„€μΉ˜κ°€ ν•„μš”
  • μžλ™μœΌλ‘œ JSON 데이터 ν˜•μ‹μœΌλ‘œ λ³€ν™˜ν•΄μ£Όλ―€λ‘œ νŽΈλ¦¬ν•˜λ‹€

Axios μ„€μΉ˜

npm install axios

Axios μ‹€μŠ΅ 예제

import axios from 'axios';

// Promise ver
axios
  .get('https://koreanjson.com/users/1')
  .then((response) => {
    const { data } = response;
    console.log(data);
  })
  .catch((error) => console.log(error));

// Async / Await ver
// async function request() {
//   const response = await axios.get('https://koreanjson.com/users/1');
//   const { data } = response;
//   console.log(data);
// }

// request();

const appDiv = document.getElementById('app');
appDiv.innerHTML = `
<h1>Axios ☺️</h1>
<h3>console 창을 ν™•μΈν•΄μ£Όμ„Έμš”! πŸ‘‡πŸ‘‡πŸ‘‡</h3>
`;
profile
기둝을 μ •λ¦¬ν•˜λŠ” 곡간!

0개의 λŒ“κΈ€