Redux-Saga 无法正确读取来自 fetch 的响应 api
Redux-Saga not able to correctly read response from fetch api
嗨,我如何读取从获取调用返回的数据:
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]
我如何从这个承诺中得到我的"info"(边数组[7]?我是新手。谢谢
response.json() 是异步的并且 returns promise
改变这个
const res = response.json()
至
const res = yield response.json()
webpackbin 例子
嗨,我如何读取从获取调用返回的数据:
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]
我如何从这个承诺中得到我的"info"(边数组[7]?我是新手。谢谢
response.json() 是异步的并且 returns promise
改变这个
const res = response.json()
至
const res = yield response.json()
webpackbin 例子