批改状态:合格
老师批语:
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>fetch / async / await 的使用场景</title></head><body><script>// fetch的使用fetch("https://jsonplaceholder.typicode.com/todos/7")// 获取一些json数据,在项目中进行测试.then(function (response) {return response.json()}).then(function (json) {console.log(json)})</script><script>// async / await的使用// function 前添加 async , 转为异步函数async function getUser() {let url = 'https://jsonplaceholder.typicode.com/todos/7';// 1. 等待结果再进行下一步操作,返回响应对象const response = await fetch(url);// 2. 将响应结果,转为json, json()const result = await response.json();console.log(result);}</script></body></html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号