简体   繁体   中英

axios promise value returns undefined in Chrome console and a string in Firefox console

when the following is executed the "console.log" it returns nothing in Chrome (Version 60.0.3112.101 ) but a string in Firefox (54.0).

axios.get('https://jsonplaceholder.typicode.com/posts')
.then(function (response) {
  console.log(response.data[0].title);
})
.catch(function (error) {
  console.log(error);
});  

note that if "alert" is used in Chrome instead of "console.log" it works fine. Is there any way to make it work in Chrome?

thanks for any help.

If I add axios to this page (here on SO), then run that code in Chrome's console, I see this in Chrome:

在此处输入图片说明

If you're referring to the undefined in , [[PromiseValue]]: undefined , ignore it. That's just the display of the Promise object returned by catch , which isn't settled yet (thus has no fulfillment value or rejection reason). That has nothing to do with the ultimate settlement of the promise, which as you can see at the bottom of that picture, is the string with the first title.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM