최근에 ajax 요청을 위해 가장 많이 사용되는 라이브러리는 axios이다.
이 axios를 사용해서 GET, POST, PUT, DELETE 요청을할 수 있는데 사용법은 매우 간단하다.
GET
import axios from 'axios';
axios.get(url).then((res) => {
// res.json();
})
.catch((err) => {
});
POST
import axios from 'axios';
axios.post(url, data).then((res) => {
return res.json();
})
.catch((err) => {
});
위의 get, post 함수를 사용하는 대신 아래처럼 전체 configuration을 설정해서 사용하는 방법도 있다.
axios({
method: 'post', // get, post, put, delete 모두 가능
url: {url},
data: {}
});
'#IT 글로써' 카테고리의 다른 글
JavaScript - 캡슐화 encapsulation (1) | 2021.03.02 |
---|---|
JavaScript - "is a" and "has a" (0) | 2021.02.26 |
JavaScript - storeScrollPosition & restorePosition (0) | 2021.02.21 |
CSS - 줄바꿈 word-break & word-wrap #2 (0) | 2021.01.24 |
CSS - 줄바꿈 word-break & word-wrap #1 (0) | 2021.01.24 |