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

v v*_*v v 0 api header reactjs 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?"
Run Code Online (Sandbox Code Playgroud)

如果用于ng-admin调用后端API,则效果很好.

Ash*_*aha 5

您需要在响应中添加名为"X-Total-Count"的标题来解决此问题."X-Total-Count"的值应等于记录总数.

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

它被用于分页.

例如,我在这里附上了Chrome开发工具的屏幕截图.

在此输入图像描述