json-server疾速地依据json文件,生成接口 前端的形式写真的假接口
一、装置json-server
npm install -g json-server
查看版本号,装置胜利
json-server -v
0.17.0
二、创立db.json
在文件夹下创立一个db.json文件,寄存一些数据。
{
"posts": [
{
"id": 1,
"title": "json-server",
"author": "typicode"
}
],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
}
],
"profile": {
"name": "typicode"
}
}
三、启动json-server
进入文件夹,间接在地址栏cmd,进入终端。执行启动json-server命令。
json-server --watch .\db.json --port 5222
或者 json-server db.json
json-server 曾经启动胜利。
四、查看数据
在浏览器中输出地址:http://localhost:+端口号/接口名称,即可查看数据。
五、public目录
在和db.json同级的目录下,创立public目录,外面能够寄存一些动态资源。
发表回复