方式1:手动实现finally() //简单亲测可用
引入的js后加入
<script>
Promise.prototype.finally = function (callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback()).then(() => value),
reason => P.resolve(callback()).then(() => { throw reason })
);
};
</script>
方式2:借助promise.prototype.finally包
npm install promise-prototype-finally
最后记得在 main.js 里引入该依赖包:
const promiseFinally = require('promise.prototype.finally');
// 向 Promise.prototype 增加 finally()
promiseFinally.shim();
// 之后就可以按照上面的使用方法使用了
借鉴资料
https://segmentfault.com/a/1190000015550213
https://blog.csdn.net/weixin_41828535/article/details/88949659
来源:oschina
链接:https://my.oschina.net/berzhuan/blog/4298030