vue.js搭建用户管理系统练手(一)----配置json-server

我们在测试功能的时候,往往需要后台的数据,如果后台的数据没有的时候,我们可以用json-server来实现快速实现简单的数据模拟!

  1. 使用前提
    安装node.js,使用node -v测试安装是否成功
  2. npm install -g json-server 全局安装json-server
  3. 在随意一个文件夹新建db.json
{
  "users": [
    { "name": "Henry", "phone": "13260582198", "email": "[email protected]", "id": "1", "age": "30", "compandyId": "1" },

    { "name": "Emily", "phone": "13260582198", "email": "[email protected]", "id": "2", "age": "5", "compandyId": "2" },

    { "name": "lili", "phone": "13260582198", "email": "[email protected]", "id": "3", "age": "16", "compandyId": "3" },

    { "name": "fv", "phone": "13260582198", "email": "[email protected]", "id": "4", "age": "18", "compandyId": "3" },

    { "name": "cons", "phone": "13260582198", "email": "[email protected]", "id": "5", "age": "29", "compandyId": "1" }
  ],
  "companies":[{
     "id":"1",
     "name":"apple",
     "description":"Apple is good"
  },
  {
     "id":"2",
     "name":"google",
     "description":"google is good"
  },{
     "id":"3",
     "name":"micro",
     "description":"micro is good"
  }]

}

4 在该文件夹下打开命令行:

json-server –watch db.json

5 访问http://localhost:3000/users 出现相应数据即成功,同理http://localhost:3000/companies也同样有数据

猜你喜欢

转载自blog.csdn.net/suresand/article/details/80905749