简体   繁体   English

axios promise值在Chrome控制台中返回undefined,在Firefox控制台中返回字符串

[英]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). 当执行以下命令时,“ console.log”在Chrome(版本60.0.3112.101)中不返回任何内容,而在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. 请注意,如果在Chrome中使用“ alert”而不是“ console.log”,则可以正常工作。 Is there any way to make it work in Chrome? 有什么方法可以使其在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: 如果我将axios添加到此页面(此处在SO上),然后在Chrome的控制台中运行该代码,则我会在Chrome中看到以下内容:

在此处输入图片说明

If you're referring to the undefined in , [[PromiseValue]]: undefined , ignore it. 如果你指的是undefined, [[PromiseValue]]: undefined ,忽略它。 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). 那只是catch返回的Promise对象的显示,尚未解决(因此没有实现价值或拒绝原因)。 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. 这与承诺的最终解决无关,正如您在图片底部看到的那样,它是带有第一个标题的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Axios在控制台上打印值,但返回未定义 - Axios prints value on console but returns undefined 为什么 Chrome 和 FireFox 控制台打印“未定义”? - Why does Chrome & FireFox console print 'undefined'? 可以删除 Chrome 和 Firefox 控制台中的“未定义”调用吗? - Can the 'undefined' call in Chrome and Firefox console be removed? 返回返回未定义但控制台返回值 - Return returns undefined but console returns value 如何在Firefox / Chrome控制台中显示文档字符串? - How to show documentation string in Firefox / Chrome console? 调用javascript函数,值在控制台中返回为undefined - Calling a javascript function, value returns as undefined in the console async/await 记录到控制台但不返回任何值并返回 `Promise { pending }` - async/await logs to the console but returns no value and returns `Promise { pending }` Chrome/Firefox console.log 总是附加一行“未定义” - Chrome/Firefox console.log always appends a line saying 'undefined' 为什么 Firefox 和 Chrome 控制台中像“}{”这样的结构会返回“未定义”? - Why does a construction like '}{' in the Firefox and Chrome console return 'undefined'? 承诺始终在 Chrome 控制台中挂起 - Promise always pending in Chrome console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM