redux-saga call fetch json Failed to execute 'json' on 'Response': Illegal invocation

Failed to execute 'json' on 'Response': Illegal invocation

// 问题复现
{
	*getData(_, { call, put }) {
		 // 获取数据
		 const res = yield call(fetch, '/api/list');
		 const list = yield call(res.json); //  Failed to execute 'json' on 'Response': Illegal invocation 
		put({
			type: 'change',
			payload: list
		});
	},
}

问题分析

查看相关文档

Body.json()
Body mixin 的 json() 方法接收一个 Response 流,并将其读取完成。它返回一个 Promise,Promise 的解析 resolve 结果是将文本体解析为 JSON。

**可以看到 jsonMIXIN的方法 分析可能是json 上下文被 call 对象改变 **

问题解决

手动绑定上下文

const list = yield call(res.json.bind(res));