Fetch 与 Promise
来源:互联网 发布:如何做金融投资 知乎 编辑:程序博客网 时间:2024/05/22 02:12
Fetch
javascript 异步请求
具体标准参考如下 点击这里
FetchAPI
基本用法(ES6 语法):
fetch(url,option) .then((response) => { // do something });
其中
const option = { method: 'POST', head: { Accept: 'application/json', 'Content-type': 'application/json', Authorization: `Basic ${btoa(`${username}:${password}`)}`, }, body: ...}
Promise
一种JavaScript对象,用来异步运算。
语法:
new Promise( /* executor */ (resolve, reject) => { //});
当executor 会立马调用,在Promise 构造函数返回创建的对象前。 resolve 和 reject 函数将会被调用。 通常executor用来初始化一些异步工作。
Promise 有三个状态
- pending : 初始化状态,没有完成或拒绝
- fulfilled: 操作成功完成
- rejected: 操作失败
一个pending 的promise 可以fulfilled一个值,或者rejected带有一个error。当这些都发生后,then 方法会被调用。
Promise().then(() => { // first return Promise.reject(); // second then will not be called. }).then( () => { // second })
0 0
- Fetch 与 Promise
- fetch+promise
- Promise,Ajax,fetch
- Promise with fetch and post
- 前端使用fetch报promise未定义
- Promise , fetch Api ,blueBird,Q,When
- React-Native Fetch使用Promise封装(一)
- 使用Promise异步发送多个fetch
- React Native 网络请求封装:使用Promise封装fetch请求
- React Native 网络请求封装:使用Promise封装fetch请求
- React Native 网络请求封装:使用Promise封装fetch请求
- React Native 网络请求封装:使用Promise封装fetch请求
- 异步JavaScript与Promise
- Future与Promise
- Promise与deferred
- Promise与setTimeout
- Promise详解与使用
- join与fetch详解
- 13.1.3 理解工作流的原理
- Rime协议学习笔记:(十二)netflood洪泛技术
- 应用程序创建layer的流程
- 13.1.4 创建工作流基本操作
- Array对象
- Fetch 与 Promise
- 测试代码(a + b problem)
- shell使用笔记
- POJ - 3280 Cheapest Palindrome
- Java——StringBuffer和StringBuilder
- hdu -Monkey and Banana
- Java内存模型——锁
- 找出字串的最长重复子串
- IIS下虚拟目录或应用程序不继承根web.config的解决方法