1. 先安装
npm install json-server -g
2.查看是否安装成功
json-server -h
3.准备数据,新建一个文件夹 mock,cd mock,在mock下 新建test.json
{
"list": [
{
"id": ,
"title": "bim项目启动了",
"date": "2018-08-12",
"likes": ,
"views":
},
{
"id": ,
"title": "bim项目启动了",
"date": "2018-08-12",
"likes": ,
"views":
}
],
"comments": [
{
"id": ,
"news_id": ,
"data": [
{
"id": ,
"content": "测试数据"
},
{
"id": ,
"content": "测试数据"
}
]
}
]
}
4.在mock下执行如下代码 -p是指定端口
json-server -w test.json -p 8001
5.然后访问 http://localhost:8001/db 可以查看 test.json 文件中所定义的全部数据