finally 回调中的 axios 响应对象未定义

Ama*_*ngh 3 javascript es6-promise axios vuejs2

我在我的 Vue.js 项目之一中使用 axios。无论 API 调用失败还是完成,我都在执行一些操作。我开始了解finnaly()方法。它在 API 请求失败或成功后执行。但是我没有在最终给出的回调中得到响应对象。

例如:

axios()
.then((response) => {
  console.log(response); // response object defined
  //handle response on success
  return response
}).finally((response) => {
  console.log(response); // response object undefined
});
Run Code Online (Sandbox Code Playgroud)

Dha*_*Pai 5

Promise.finally 方法不为回调提供参数

阅读 MDN [ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally ]

您可以再次使用 .then 来获取响应。