配置json-server
阿新 • • 發佈:2018-12-22
1.全域性安裝json-server【可能需要管理員許可權】
npm i -g json-server
2.建立資料夾jsonerver,初始化package.json檔案
npm init
3.區域性安裝json-server
npm i json-server --save
4.修改package.json檔案,配置啟動方式
"scripts":{
"json:server":"json-server --watch db.json"
}
5.建立db.json檔案
{ "users":[ { "name":"zs", "phone":"123", "email":"[email protected]", "id":1, "age":12, "companyid":1 }, { "name":"ls", "phone":"234", "email":"[email protected]", "id":2, "age":13, "companyid":2 }, { "name":"ww", "phone":"345", "email":"[email protected]", "id":3, "age":14, "companyid":3 }, { "name":"cl", "phone":"456", "email":"[email protected]", "id":4, "age":15, "companyid":3 } ], "companies":[ { "id":1, "name":"Apple", "des":"apple is good" }, { "id":2, "name":"ms", "des":"ms is good" }, { "id":3, "name":"gg", "des":"gg is good" } ] }
6.執行
npm run json:server
localhost:3000/xxx
只能執行一個3000的埠,如果含有另一個3000埠,會執行不成功