react-admin fetch header X-Total-Count问题

时间:2018-06-14 08:47:10

标签: reactjs api header react-admin

从前端使用react-admin来调用后端API时,从浏览器控制台获取此错误:

Warning: Missing translation for key: "The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?"

如果使用ng-admin来调用后端API,则效果很好。

1 个答案:

答案 0 :(得分:5)

您需要添加名为" X-Total-Count"在你的回答中解决这个问题。 " X-Total-Count"的值应该等于记录总数。

假设您正在提取注释列表,数据库中总共有125条注释,您可以从中获取25条记录。那么" X-Total-Count"的值应该是125。

它被用于分页。

例如,我在此附上了Chrome开发工具的屏幕截图。

enter image description here