admin管理员组

文章数量:1297094

I am using axios in one of my Vue.js project. I am performing some operations no matter if an API call fails or pletes. I came to know about finnaly() method. It is being executed after the API request either fails or succeeds. But I am not getting response object in callback given to finally.

For Example:

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

I am using axios in one of my Vue.js project. I am performing some operations no matter if an API call fails or pletes. I came to know about finnaly() method. It is being executed after the API request either fails or succeeds. But I am not getting response object in callback given to finally.

For Example:

axios()
.then((response) => {
  console.log(response); // response object defined
  //handle response on success
  return response
}).finally((response) => {
  console.log(response); // response object undefined
});
Share edited Feb 7, 2019 at 8:39 Billal BEGUERADJ 22.8k45 gold badges123 silver badges140 bronze badges asked Feb 7, 2019 at 8:35 Amarjit SinghAmarjit Singh 2,1541 gold badge24 silver badges54 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

The Promise.finally method does not give arguments to the callback

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

You could use .then again to get the response.

I solved it by including polyfill.finally script:

<script src="https://polyfill.io/v3/polyfill.min.js?features=Promise.prototype.finally" defer></script>

本文标签: javascriptaxios response object in finally callback is undefinedStack Overflow