Try   HackMD

用 axios 串接 API|筆記 by Sz

tags: Sz 課前 Vue新手夏令營

他是一個 promise base 的外掛,可以使用他的語法來進行串接

環境建置:使用 CDN 版本

axios 外掛在這

在 html 匯入 cdn

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

取得遠端資料

axios.get('https://randomuser.me/api/') .then(res => { // 通常 res 會是多項資料,取出需要的部份 console.log(res.data.results); }) // err.response 是固定用法 .catch(err => { console.log(err.response); })