vue.js搭建使用者管理系統練手(一)----配置json-server

lightTrace發表於2018-07-03

我們在測試功能的時候,往往需要後臺的資料,如果後臺的資料沒有的時候,我們可以用json-server來實現快速實現簡單的資料模擬!

  1. 使用前提
    安裝node.js,使用node -v測試安裝是否成功
  2. npm install -g json-server 全域性安裝json-server
  3. 在隨意一個資料夾新建db.json
{
  "users": [
    { "name": "Henry", "phone": "13260582198", "email": "986245320@qq.com", "id": "1", "age": "30", "compandyId": "1" },

    { "name": "Emily", "phone": "13260582198", "email": "986245320@qq.com", "id": "2", "age": "5", "compandyId": "2" },

    { "name": "lili", "phone": "13260582198", "email": "986245320@qq.com", "id": "3", "age": "16", "compandyId": "3" },

    { "name": "fv", "phone": "13260582198", "email": "986245320@qq.com", "id": "4", "age": "18", "compandyId": "3" },

    { "name": "cons", "phone": "13260582198", "email": "986245320@qq.com", "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 db.json

5 訪問http://localhost:3000/users 出現相應資料即成功,同理http://localhost:3000/companies也同樣有資料

相關文章