我试图使用以下方法从服务器获取数据:
exports.findAll = function(req, res) {
console.log("--->Find All: \n" + JSON.stringify(articles, null, 4));
res.end(JSON.stringify(articles, null, 4)); };这是我的行动守则:
export const getArticles =()=> dispatch =>{
dispatch(ArticlesLoading());
fetch('http://localhost:8000/api/articles/')
.then(handleErrors)
.then(res => dispatch(
{
type : GET_ARTICLES,
payload: res.json()
}
))
}当我设置初始状态时,我可以看到我的文章,但是当我想从服务器读取数据时,它会遇到错误"TypeError: articles.map不是一个函数“。我记录了我的action.payload,结果如下所示:

发布于 2018-11-24 09:02:20
export const getArticles =()=> dispatch => {
dispatch(ArticlesLoading());
fetch('http://localhost:8000/api/articles/')
.then(handleErrors)
.then(res => res.json())
.then(res => dispatch({
type : GET_ARTICLES,
payload: res,
});
}res.json返回一个承诺,尝试下面的代码
https://stackoverflow.com/questions/53456640
复制相似问题