在新的 Promise 中有决心、拒绝和没有它之间有什么区别?
What is the difference between having resolve, reject in a new Promise and not having it?
这段代码是 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 与创建一个具有 resolve 和 reject to invoke .then 和 .catch 块的新 Promise 之间有什么区别?
fetch 函数返回一个 Promise 对象,因此您可以使用 .then 和 .catch 块。
这段代码是 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 与创建一个具有 resolve 和 reject to invoke .then 和 .catch 块的新 Promise 之间有什么区别?
fetch 函数返回一个 Promise 对象,因此您可以使用 .then 和 .catch 块。