https://github.com/typicode/json-server#paginate
首先全局安装
cnpm install json-server -g
// mac下执行
sudo cnpm install json-server -g
在目录下创建一个server文件夹,将data.json文件放在里面
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
cd server 进入server文件夹
执行下列命令
json-server --watch data.json --port 3002
数据启动成功
http://localhost:3002/jokes?_page=2&_limit=5 表示第2页,一页5条
http://localhost:3002/jokes?&q=why 表示查询why这个字段
这说明接口已经可以使用了