首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError: articles.map不是使用react的函数

TypeError: articles.map不是使用react的函数
EN

Stack Overflow用户
提问于 2018-11-24 08:54:17
回答 1查看 45关注 0票数 0

我试图使用以下方法从服务器获取数据:

代码语言:javascript
复制
exports.findAll = function(req, res) {
console.log("--->Find All: \n" + JSON.stringify(articles, null, 4));
res.end(JSON.stringify(articles, null, 4));  };

这是我的行动守则:

代码语言:javascript
复制
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,结果如下所示:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-24 09:02:20

代码语言:javascript
复制
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返回一个承诺,尝试下面的代码

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53456640

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档