STUDY/VueJS
[VueJS] axios
BYSSUZY
2020. 4. 23. 14:07
개발시 api 통신이 필요하다.
jquery를 쓸 땐, ajax를 사용했는데, 뷰에선 [axios]를 쓴다고 한다.
- HTTP통신을 위한 Javascript라이브러리
- Promise 기반
| 설치
- NPM (해당프로젝트 경로)
$ npm install axios
- CDN
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
- file
import axios from 'axios'
| GET
axios.get('...',{params:{}}).then((response)=>{
// handle success
console.log(response);
})
.catch((error)=>{
// handle error
console.log(error);
})
.then(()=>{
// always executed
});
| POST