3 回答

TA貢獻1865條經(jīng)驗 獲得超7個贊
為什么 response.json
還承諾?
response
.json()
如果我從 then
處理程序?
fetch(url).then(response => response.json().then(data => ({ data: data, status: response.status })).then(res => { console.log(res.status, res.data.title)}));

TA貢獻1802條經(jīng)驗 獲得超10個贊
fetch()
.then()
Promise
.then()
iterator.then(response => response.json().then(post => document.write(post.title)));
post
response.json()
.
Object
.then()
iterator.then(response => Promise.resolve({ data: response.json(), status: response.status }) .then(post => document.write(post.data)));
post
Object
Promise
data

TA貢獻1155條經(jīng)驗 獲得超0個贊
then
如果處理程序函數(shù):
返回一個值,然后以返回的值作為它的值來解析返回的承諾; 拋出一個錯誤,然后返回的承諾以拋出的錯誤作為其值而被拒絕; 返回一個已經(jīng)解決的承諾,然后以該承諾的價值作為其價值來解決該承諾所返回的承諾;
返回一個已經(jīng)被拒絕的承諾,然后返回的承諾以該承諾的值作為其價值而被拒絕。 返回另一個掛起的承諾對象,此時返回的承諾的解析/拒絕將在處理程序返回的承諾的解析/拒絕之后。此外,到那時返回的允諾的值將與處理程序返回的允諾的值相同。
添加回答
舉報