Skip to Content
React学习手册
book

React学习手册

by Alex Banks, Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from React学习手册
JavaScript
新特性
27
lunch: "peanut butter and jelly"
}
var dinner = "mac and cheese"
var backpackingMeals = {
...morning,
dinner
}
console.log(backpackingMeals) // {breakfast: "oatmeal",
lunch: "peanut butter and jelly",
dinner: "mac and cheese"}
Promise
对象
Promise
对象为我们提供了一种更合理的方式处理异步行为。当创建一个异步请求
时,会产生下列两种结果之一:一切都符合预期地进行或者存在一个错误。可能存在
若干种成功的或不成功的请求。比如我们可以尝试多种方式获取数据来达成目标。我
们也会接收到多种错误提示。
Promise
对象为我们提供了一种简单的方式,将结果简
化为通过或者失败。
接下来创建一个异步
Promise
对象,用于从
randomuser.me
API
加载数据。该
API
包含
诸如
email
地址、姓名、电话号码,地址等伪成员信息,非常适合生成虚拟数据。
getFakeMembers
函数会返回一个新的
Promise
对象,它会向上述
API
发送一个请求。如
Promise
对象请求成功,那么将会加载相关数据,否则将会报错:
const getFakeMembers = count => new Promise((resolves, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React快速上手开发

React快速上手开发

Stoyan Stefanov
流畅的Python

流畅的Python

Luciano Ramalho
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787519814236