业务场景:提交某个表单时,为了防止重复提交,提交后按钮需要置灰,直到提交完成按钮才可点击。如果没有finally函数,则需要在then和catch里都写入恢复按钮的代码,但是有了finally函数,我们只需要把这段代码写入函数中即可,因为finally函数中的逻辑,请求完成之后无论是成功失败都会被执行
使用方法:
1、 npm i promise.prototype.finally –S
2、 在main.js中引用, require(“promise.prototype.finally”).shim();
3、 在调用接口的时,
Add()
.then(res => {
})
.catch(err => {
})
.finally(()=>{ })