Angular5學習筆記 - 虛擬RestfulApi配置與使用(六)
阿新 • • 發佈:2018-01-30
window com scripts mac restfu alt 新建 服務 src
一、安裝json-server功能
#windows cnpm install json-server -g #Mac & Linux sudo npm install json-server -g
二、配置數據
新建db.json文件
{ "news":[ { "key" : "1", "name" : "阿東", "age" : 32, "address": "銀河系1號" }, { "key" : "2","name" : "小李", "age" : 42, "address": "銀河系2號" }, { "key" : "3", "name" : "小張", "age" : 32, "address": "銀河系3號" } ], "comments":[ { "id": 1, "news_id": 1, "data": [ {"id": 1, "content": "支持黨中央決定" }, { "id": 2, "content": "抄寫黨章勢在必行!" } ] } ] }
三、配置啟動快捷方式
新建文件package.json
{ "scripts": { "mock": "json-server db.json --port 3003" } }
四、啟動虛擬服務器
進入到該目錄執行
npm run mock
五、效果
Angular5學習筆記 - 虛擬RestfulApi配置與使用(六)