1.2.2 使用json-server 服务端(帮助我们自动搭建http服务)
在线文档: https://github.com/typicode/json-server
1.下载: npm install -g json-server
2.目标根目录下创建数据库 json 文件: db.json
{
“posts”: [
{ “id”: 1, “title”: “json-server”, “author”: “typicode” },
{ “id”: 2, “title”: “json-server2”, “author”: “typicode” }
],
“comments”: [
{ “id”: 1, “body”: “some comment”, “postId”: 1 }
],
“profile”: { “name”: “typicode” }
}
3.启动服务器执行命令: json-server —watch db.json(在db.json所在文件夹的集成终端下执行 报错时用管理员方式打开vscode)
