--- tags: 軟體工程師體驗營 - 2023 --- # 🏅 JS 任務 Day24 - axios get 串接練習 ### axios - get 請記得載入 axios 的 CDN ```htmlembedded= <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.4.0/axios.min.js"></script> ``` #### axios 的 get 語法可以用來取得遠端伺服器的資料 ```javascript= // 在以下 URL 的部分填入 API 網址 axios.get('URL') // 如果連接成功,可以用 then() 處理傳回來的值,將回傳結果儲存於 response。 .then(function (response) { console.log(response); }); ``` 問題 --- 請同學嘗試用 axios 串接這個 API 並透過程式碼 `console.log` 輸出以下要求: API url:`https://data.coa.gov.tw/api/v1/PlantEpidemicType/?Year=2023` 1. 請輸出該資料中 Data 陣列內總共有多少個物件? 2. 請輸出 Data 陣列內的第一筆物件,屬性 PubDate 所對應的值。 3. 請輸出 Data 陣列內的第一筆物件,屬性 Subject 所對應的值。 4. 請輸出 Data 陣列內的第一筆物件,屬性 Issue 所對應的值。 5. 請輸出 Data 陣列內的第一筆物件,屬性 PlantName 所對應的值。 6. 請輸出 Data 陣列內的第三筆物件,屬性 City 所對應的值。 7. 請輸出 Data 陣列內的第二筆物件,屬性 Body 所對應的值。 9. 請輸出 Data 陣列內的最後一筆物件,屬性 Prescription 所對應的值。 ## 回報流程 1. 將答案貼在 Codepen 並複製 Codepen 連結貼至「回報區」回報 (也可以將答案直接貼至「回報區」)  <!-- 解答: axios.get('https://data.coa.gov.tw/api/v1/PlantEpidemicType/?Year=2023') // 如果連接成功,可以用 then() 處理傳回來的值,將回傳結果儲存於 response。 .then(function (response) { console.log(response.data.Data.length); console.log(response.data.Data[0].PubDate); console.log(response.data.Data[0].Subject); console.log(response.data.Data[0].Issue); console.log(response.data.Data[0].PlantName); console.log(response.data.Data[2].City); console.log(response.data.Data[1].Body); console.log(response.data.Data[response.data.Data.length-1].Prescription); }); --> 回報區 --- | 報數 | Discord 名字 | Codepen/其他回饋 | |:----:|:-------------------:|:---------------------------------------------------------------------------------------------------------------------------------:| | 1 | Rochel#4754 | [Codepen](https://codepen.io/rochelwang1205/pen/xxyNLJe) | | 2 | Berlin#7338 | [Codepen](https://codepen.io/3qberlin/pen/WNaBZeM) | | 3 | Tami#6742 | [Codepen](https://codepen.io/wqsdqbjn-the-vuer/pen/jOeoLgx) | | 4 | Billy_Ti#9716 | [Codepen](https://codepen.io/Ti-Show/pen/oNaRGBx?editors=0012) | | 5 | 銀光菇#1692 | [Codepen](https://codepen.io/genesynthesis/pen/abRrLmb) | |6|雲漢#5319|[codepen](https://codepen.io/keon981/pen/wvYbrPj?editors=1011)| |7| Quantum#6093|[Codepen](https://codepen.io/Min-Hao-Hung/pen/YzJbrrZ)| |8| Snadra#1987|[Codepen](https://codepen.io/mlqmhltg/pen/vYVwevW)| |9| Eero#1147|[Codepen](https://codepen.io/Eero-Chiao/pen/vYVwWLj)| |10| 翔.#0859|[Codepen](https://codepen.io/energy95272z/pen/BaqemZE?editors=0012)| |11| Jacky7035#9423 |[Codepen](https://codepen.io/adens123/pen/mdzYpPb)| |12|peihsuan#6315|[Codepen](https://codepen.io/peihsuanlai/pen/MWPdEmx)| |13|K(アギルダー)#0386|[Codepen](https://codepen.io/klay376014/pen/qBJGpVv)| | 14 | 辣椒#1002 | [Codepen](https://codepen.io/chilichen118/pen/gOBJozr) | | 15 | Kulimusoda#2785 | [Codepen](https://codepen.io/yuch3n_chen/pen/abRrEeg?editors=0011) | | 16 | ChaosTu#9311 | [Codepen](https://codepen.io/torotu/pen/eYPaybP?editors=0012) | | 17 | gahwa#3562 | [Codepen](https://codepen.io/gahwa17/pen/dygEdrR) | | 18 | henrykgb#5749 | [Codepen](https://codepen.io/henrymorgan666/pen/dygEmwq) | 19 | jia yu#8896 | [Codepen](https://codepen.io/fjqxaznl-the-reactor/pen/PoyvaXe) | 20 | Akira#9996 | [Codepen](https://codepen.io/Akira-Chen/pen/eYPajpJ) | 21 | 姜承#8204 | [Codepen](https://codepen.io/Troy0718/pen/wvYbxpL) | 22 | wiimax#4564 |[Codepen](https://codepen.io/willismax/pen/eYPaLRM?editors=0011) |23|Yvonne#2721|[Codepen](https://codepen.io/Evonne/pen/eYPaLPj?editors=0011) |24|Uli#1946|[Codepen](https://codepen.io/uli1313/pen/XWxwBZM) |25|Jennifer Chuang#3937 | [Codepen](https://codepen.io/yujhen/pen/RwemeBZ?editors=1011) | | 29 |N0c7iluc3n7#4390 | [Codepen](https://codepen.io/huang-yu-cheng/pen/VwEOVwM) | | 30 |David0799#4415 | [Codepen](https://codepen.io/David0799/pen/ExdzOvm) | | 31 | snow#0255 | [Codepen](https://codepen.io/snow21723/pen/zYmQywa) | | 32 | 鄭舜仁#6606 | [Codepen](https://codepen.io/randomno/pen/eYPwmOR) | | 33 | JimWang#6134 | [Codepen](https://codepen.io/Jim-Wang-the-selector/pen/VwEJYrO?editors=0012) | | 34 | yoyo#1003 | [Codepen](https://codepen.io/crpbugqy-the-typescripter/pen/xxyowWL) | |35|PayRoom#8328|[CodePen](https://codepen.io/water38198/pen/JjmQOOJ)| |36|townyuan#2653|[CodePen](https://codepen.io/townyuan/pen/rNqXeVr)| |37|HsuanTang#1349|[CodePen](https://codepen.io/HsuanTang/pen/mdzNaaZ)| |38|Janet#2784|[CodePen](https://codepen.io/janetlinnn/pen/bGQbEzV?editors=0011)| |39|SKey#9905|[CodePen](https://codepen.io/Dale-Chien/pen/poQzBBE)| |40|liam9930#4129|[CodePen](https://codepen.io/jgnjfvvt-the-lessful/pen/YzRzERZ)| |41|兔子#6746|[CodePen](https://codepen.io/CarrotDetector/pen/MWzWrra)| |42|JasonChang#7847|[CodePen](https://codepen.io/jsonChangJava/pen/VwVLerb)| |43|肉個阿倫#7172|[Codepen](https://codepen.io/i9574385/pen/XWybgVP)| | 44 | Kaya#8857 | [Codepen](https://codepen.io/laron9486/pen/XWyXqEO) | | 45 | FanJJ#8061 | [Codepen](https://codepen.io/yfchenn/pen/XWydPzB?editors=1111) | | 46 | PoWei#8484 | [Codepen](https://codepen.io/harrison-wei-lai/pen/rNQmroQ?editors=1111) | | 47 | Ann Chou#0146 | [Codepen](https://codepen.io/annchou_illu/pen/ExOvGOB) | | 48 | hoyiiiii | [Codepen](https://codepen.io/hoyii/pen/ZYzQmmy?editors=1011) |
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up