控制异步操作 函数前面用async修饰await 后面的是一个Promise对象【里面包含的一般是异步请求】 async function showAvatar() { //自己定义一个JSON 从里面取到一个含有name属性的对象 {name:"aaa"} let user = await AJAX('./resource/demo.json') let githubResponse = await fetch("https://api.github.com/users/" + user.name) console.log("githubResponse",githubResponse) let githubUser = await githubResponse.json() // 展示头像 let img = document.createElement('img') img.src = githubUser.avatar_url img.className = 'promise-avatar-example' document.body.append(img) // 等待3s await new Promise((resolve, reject) => { setTimeout(resolve, 3000) }) img.remove() return githubUser } showAvatar() 在react 中使用async + await 需要 安装 一些配置 因为 这个属于ES7语法,需要bable去解析