npm install json-server --save
- 创建一个json文件,格式类似
{
"user": [
{ "id": 1, "userName": "tt", "password": "1125" }
],
"content": [
{ "id": 1, "des": "a girl", "liking": "singing reading and coding" }
],
"friends": [
{"id": 1, "name": "tom", "age": "18" },
{"id": 2, "name": "tina", "age": "20" },
{ "id": 3, "name": "hell", "age": "16" }
]
}
- 在package.json文件的启动项中添加
"server": "json-server data.json"
- 在终端输入npm server,生成以下3个api接口