您好如何读取从提取呼叫返回的数据:
export function* fetchMessages(channel) {
yield put(requestMessages())
const channel_name = channel.payload
try {
const response = yield call(fetch,'/api/messages/'+channel_name)
const res = response.json()
console.log(res)
yield put(receiveMessages(res,channel))
} catch (error){
yield put(rejectMessages(error))
}
}
当我在console.log(res)时,我得到:
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
__proto__
:
Promise
[[PromiseStatus]]
:
"resolved"
[[PromiseValue]]
:
Array[7]
如何获取我的"信息" (这个承诺的侧面阵列[7]?我对这一切都不熟悉。谢谢
答案 0 :(得分:2)
response.json()是异步并返回承诺
更改此
const res = response.json()
到
const res = yield response.json()