# 用 axios 串接 API|筆記 by Sz ###### tags: `Sz` `課前` `Vue新手夏令營` - [Vue 新手夏令營 課程頁面](https://hackmd.io/@dbFY0UD9SUeKmNXhWf01ew/BkJoW-hn_/%2FC05go-8iTSS-nrMwKU22kA) - [:sun_with_face:筆記入口](/2JiZbCPdR0G4p5fNycPmTg) 他是一個 promise base 的外掛,可以使用他的語法來進行串接 ## 環境建置:使用 CDN 版本 > [axios 外掛在這](https://github.com/axios/axios) ### 在 html 匯入 cdn ```htmlembedded= <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> ``` ## 取得遠端資料 ```javascript= axios.get('https://randomuser.me/api/') .then(res => { // 通常 res 會是多項資料,取出需要的部份 console.log(res.data.results); }) // err.response 是固定用法 .catch(err => { console.log(err.response); }) ```