js - fetch()

kiseon·2024년 7월 31일
0

TIL

목록 보기
8/26
post-thumbnail

fetch

js 비동기 함수
데이터를 요청(input/output)하는 함수로 IO통신이 일어난다.

fetch().then().then()

GET

fetch('요청 주소', { method : "GET" })   
        .then(res => res.json())         
        .then(res => {                  
            setValue(res);
        }); 

POST

fetch("요청 주소", {
            method : "POST", 
            headers : { 
                "Content-Type":"application/json; charset=utf-8"
            },body: JSON.stringify(data)  })
          .then(res=>res.json())        
          .then(res=> {
            console.log(res);          
          });

• 이벤트 핸들러를 사용하는 경우
• 타이머 함수 사용하는 경우
• 클린업(Clean-up) 함수란?

profile
되고싶다.. 개발자..!

0개의 댓글