JS 直播班 - 2021 秋季班
請同學觀看完 參考章節影片 再進行作答。
記得先載入 axios 的 CDN
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
HTML
<p class="title"></p>
JS
let arr = []; axios.get('https://hexschool.github.io/ajaxHomework/data.json').then(function(response){ console.log('資料有回傳了'); // 順序 ? arr = response.data; renderData(); }) function renderData(){ console.log(arr); // 順序 ? } console.log(arr); // 順序 ?
. 2. 承上題,如果希望加入以下 JS,讓 class 為 title 的 p 標籤可以正常的呈現「王小名」這三個字,則應該將以下 JS 填入區間 1 還是區間 2 ?
const title = document.querySelector('.title'); title.textContent = arr[0].name;
填入區間
let arr = []; axios.get('https://hexschool.github.io/ajaxHomework/data.json').then(function(response){ console.log('資料有回傳了'); arr = response.data; renderData(); }) function renderData(){ console.log(arr); // 區間 1 } console.log(arr); // 區間 2
將答案寫在 CodePen 並複製 CodePen 連結貼至 thread 中回報就算完成了喔! 解答請參考下圖(需打開程式碼的部分觀看)
Image Not Showing Possible Reasons The image file may be corruptedThe server hosting the image is unavailableThe image path is incorrectThe image format is not supported Learn More →
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up