개발하는 루루언니

axios 공식 본문

컴퓨터 정보/리액트

axios 공식

혜닝혜루 2022. 11. 12. 21:55
728x90
반응형

get

import axios from 'axios';
//const axios = require('axios'); // legacy way

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });

 

1. import 

2.  주소 가져오기 

3. then 성공한 데이터 (res) 들어옴 ( 200대)

4. 그걸 바로 사용할수 있음 ( console.log (res)

5. 에러난걸 캐치 할 수 있음 catch ( error) (400대)

 


Post

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
728x90

'컴퓨터 정보 > 리액트' 카테고리의 다른 글

useLocation  (0) 2022.11.13
useQuery 공식  (0) 2022.11.12
Tanstack Query 사용해보기  (0) 2022.11.11
outlet 사용하는법 : 페이지 전체를 랜더링 X  (0) 2022.11.11
라우팅 vs 클라이언트 사이드 라우팅  (0) 2022.11.11