axios.post(...).then(...).catch(...).finally is not a function解决办法

青春壹個敷衍的年華 提交于 2020-07-26 23:30:54

方式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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!