js Promise finally All In One

finally


let isLoading = true; fetch(myRequest).then(function(response) {
var contentType = response.headers.get("content-type");
if(contentType && contentType.includes("application/json")) {
return response.json();
}
throw new TypeError("Oops, we haven't got JSON!");
})
.then(function(json) { /* process your JSON further */ })
.catch(function(error) { console.error(error); /* this line can also throw, e.g. when console = {} */ })
.finally(function() { isLoading = false; });

promise 兜底



async fetchAdjustBindMaster (params) {
this.fullscreenLoading = true;
const {
data,
// data: {
// // status,
// msg,
// },
status,
} = await postAdjustBindMaster(params)
.catch(err => console.log(' promise error', err))
.finally((ok, err) => {
console.log(' promise finally 兜底', ok, err);
this.fullscreenLoading = false;
});
console.log(' status =', status, data);
// this.fullscreenLoading = false;
// if(status === 200) {
// this.$message({
// message: '成功!',
// type: 'success',
// });
// this.closeModal();
// this.fetchTabListByMenuKey(true);
// this.$emit('refreshTable', false);
// } else {
// this.$message({
// message: `${data?.msg ?? '失败,请重试!'}`,
// type: 'error',
// });
// }
// this.$emit('refreshTable', false);
},

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有️xgqfrms, 禁止转载 ️,侵权必究️!


js Promise finally All In One的更多相关文章

  1. JS - Promise使用详解--摘抄笔记

    第一部分: JS - Promise使用详解1(基本概念.使用优点) 一.promises相关概念 promises 的概念是由 CommonJS 小组的成员在 Promises/A 规范中提出来的. ...

  2. js promise chain

    新的标准里增加了原生的Promise. 这里只讨论链式使用的情况,思考一下其中的细节部分. 一,关于 then() 和 catch() 的复习 then() 和 catch() 的参数里可以放置 ca ...

  3. [Node.js] Promise,Q及Async

    原文地址:http://www.moye.me/2014/12/27/promise_q_async/ 引子 在使用Node/JS编程的时候,经常会遇到这样的问题:有一连串的异步方法,需要按顺序执行, ...

  4. ANGULAR JS PROMISE使用

    Promise是一种模式,以同步操作的流程形式来操作异步事件,避免了层层嵌套,可以链式操作异步事件. 我们知道,在编写javascript异步代码时,callback是最最简单的机制,可是用这种机制的 ...

  5. JS Promise API

    一.描述 我们知道JavaScript语言的执行环境是“单线程”,所谓单线程,就是一次只能够执行一个任务,如果有多个任务的话就要排队,前面一个任务完成后才可以继续下一个任务. 这种“单线程”的好处就是 ...

  6. js promise 介绍和使用

    1.什么是promise js是单线程执行的. ajax是典型的异步操作,我们通常会在ajax的成功或者失败之后写上回掉函数.这中写法是一种嵌套的方式,如果回掉多了会造成代码复杂并且难以复用. pro ...

  7. [转]JS - Promise使用详解1(基本概念、使用优点)

    一.promises相关概念 promises 的概念是由 CommonJS 小组的成员在 Promises/A 规范中提出来的.   1,then()方法介绍 根据 Promise/A 规范,pro ...

  8. [转]JS - Promise使用详解2(ES6中的Promise)

    原文地址:https://www.hangge.com/blog/cache/detail_1638.html 2015年6月, ES2015(即 ECMAScript 6.ES6) 正式发布.其中  ...

  9. JS promise对象

    Promise 承诺 一:promise概念 在js中,promise是一个对象,是专门用来处理异步操作 / 回调地狱的,那么什么是回调地狱?设计到同步和异步任务的知识,在js中,因为js是单线程,无 ...

随机推荐

  1. autocommit 隔离级别 next lock gap lock 事务隔离级别和锁

    autocommit 隔离级别 https://www.ibm.com/developerworks/cn/opensource/os-mysql-transaction-isolation-leve ...

  2. token的分层图如下

    基于 token 的多平台身份认证架构设

  3. How Interfaces Work in Go

    research!rsc: Go Data Structures: Interfaces https://research.swtch.com/interfaces How Interfaces Wo ...

  4. 洛谷P4180

    被教练安排讲题 可恶 这道题我是十月初上课时花了一下午做出来的,当时连倍增都不会,过程比较困难,现在看看还可以 本来想口胡一发,后来想了想可能以后要用,还是写成文章吧 Description 求一棵严 ...

  5. 一个sql盲注小工具 (Golang版)

    并发,二分法判断. 源码写的有点垃圾,有点乱,结果也存在一些缺失. 记录: sql:select distinct 中的distinct选项,这是只会获取你表中不重复数据,是表中,而不是你一次sql执 ...

  6. SpringMVC听课笔记(七:Restful CRUD)

    这章貌似没有什么可讲的,可以看GitHub工程代码: https://github.com/heyboom/SpringMVC_Rest_CRUD

  7. Spring听课笔记(专题一)

    Spring入门课程:https://www.imooc.com/learn/196 第0章: Spring是为解决企业应用程序开发复杂性而创建的一个Java开源框架,应用非常广泛.业内非常流行的SS ...

  8. Django(静态文件or路由)

    静态文件 在开发中同创会使用到 css,js,img等静态文件,这里带大家简单的介绍一下django如何处理静态页面, 配置 setting.py文件 STATIC_URL = '/static/' ...

  9. Spring boot 自定义注解标签记录系统访问日志

    package io.renren.common.annotation; import java.lang.annotation.Documented; import java.lang.annota ...

  10. PHP-文件、目录相关操作

    PHP-文件.目录相关操作 一  目录操作(Directory 函数允许获得关于目录及其内容的信息) 相关函数: 函数 描述 chdir() 改变当前的目录. chroot() 改变根目录. clos ...