这个包可以快速帮我们搭建一个http服务,为什么搭建http服务呢?是因为我们使用axios的时候需要向服务端发送请求,github上可以搜索到。
json-server
1 安装
npm install -g json-server
2 创建 db.json文件
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" },
{ "id": 2, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
image.png
3 开启json server
json-server --watch db.json
image.png
4 访问
4.1 get请求获取数据
image.pngimage.png
网友评论