此代码是否是Promise?
let fetchData = fetch("https://jsonplaceholder.typicode.com/users")
.then(res => res.json())
.then(data => {
console.log(data[0].name)
})
.catch(err => {
console.log('Opps! something went wrong :(')
})
拥有这样的Promise和创建具有解决方案并拒绝调用.then和.catch块的新Promise之间有什么区别?
答案 0 :(得分:1)
fetch函数返回一个Promise对象,这就是为什么您可以使用.then和.catch块的原因。