[英]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.