1.json-server基於node.js所以需要安裝node的開發環境
https://blog.csdn.net/simba1949/article/details/79252352 安裝node
2.安裝node之後,完整成功後,安裝json-server
npm install -g json-server
3.任意文件夾下創建db.json。並添加下面內容
{ "posts": [ { "id": 1, "title": "json-server", "author": "typicode" } ], "comments": [ { "id": 1, "body": "some comment", "postId": 1 } ], "profile": { "name": "typicode" } }
4.重要的事情說好幾遍:
啓動服務的時候一定要指定--host 0.0.0.0
啓動服務的時候一定要指定--host 0.0.0.0
啓動服務的時候一定要指定--host 0.0.0.0
例如這個:
$ json-server --watch --host 0.0.0.0 --port 3000 db.json
否則不用使用ip訪問,只能使用localhost進行訪問。