学习vue-使用json-server模拟json数据

第一步:在vue项目根目录创建db.json文件夹,添加如下数据

{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

第二步:在cmd命令行状态下输入以下命令,安装json-server

npm install -g json-server

第三步:在cmd命令行进入到项目根文件夹,输入以下命令

json-server --watch db.json

在浏览器输入以下访问路径即可

http://localhost:3000/posts

http://localhost:3000/posts/1

http://localhost:3000/comments

猜你喜欢

转载自blog.csdn.net/qq_37383968/article/details/88559712