当我们执行一个promise操作时,往往伴随的是要做各种状态的修改(如请求开始时显示loading,结束时隐藏 loading), 这个状态修改,如果没有finally函数,我们需要在thencatch中都写入这段代码,但是有了finally函数,我们只需要把这段代码写入函数中即可,因为finally函数中的逻辑,请求完成之后无论是成功失败都会被执行


让 axios 支持 finally

如何支持

安装包 promise.prototype.finally

npm i promise.prototype.finally -S

使用时引用即可
require("promise.prototype.finally").shim();

 

相关文章:

  • 2022-01-18
  • 2021-12-10
  • 2021-06-10
  • 2021-10-29
  • 2021-10-26
  • 2021-10-15
  • 2021-12-22
猜你喜欢
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2021-08-23
  • 2022-03-06
  • 2021-07-17
相关资源
相似解决方案