Redux 为什么yield调用(response.json)挂起?

Redux 为什么yield调用(response.json)挂起?,redux,redux-saga,yield,Redux,Redux Saga,Yield,这是redux传奇的代码。Yield挂起并且控制台。log不打印任何内容。但是如果我将response.json替换为()=>response.json(),它就可以工作了。为什么?这是因为当您调用时,产生调用(response.json)的response.json调用的上下文错误(this) 您可以使用bind(例如yield call(response.json.bind(response)))或通过指定上下文来解决这个问题(例如yield call([response,response.

这是redux传奇的代码。Yield挂起并且
控制台。log
不打印任何内容。但是如果我将
response.json
替换为
()=>response.json()
,它就可以工作了。为什么?

这是因为当您调用
时,产生调用(response.json)
response.json
调用的上下文错误(
this

您可以使用
bind
(例如
yield call(response.json.bind(response))
)或通过指定
上下文来解决这个问题(例如
yield call([response,response.json])
),但是这里的
call实际上是无用的。你可以:

const response = yield call(fetch, `${config.backendUrl}/verify`, {
  method: 'POST'
})

const responseJson = yield call(response.json)

console.log(responseJson)

也许
call
传递的参数会导致
response.json
的行为不同。请尝试
(…args)=>{console.log(args);response.json()}
查看它们是什么
args
显示为空数组
const responseJson = yield response.json();