react-admin 获取 header X-Total-Count 问题

react-admin fetch header X-Total-Count issue

当从前端使用 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,效果很好。

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

假设您要获取评论列表,数据库中共有 125 条评论,您要从中获取 25 条记录。那么"X-Total-Count"的值应该是125.

正在用于分页。

比如这里附上Chrome开发工具的截图