本地node 服务器 json-serve

292 阅读1分钟

后端接口总是很慢怎么办?mockjs 不能增删改查怎么办?

答:json-server git地址

步骤:

  1. 全局安装json-server npm i json-server -g
  2. 在项目中创建db.json
  3. 启动服务 json-server --watch db.json
{^_^}/ hi!
  Loading db.json
  Done
  Resources
  http://localhost:3000/user
  Home
  http://localhost:3000
  Type s + enter at any time to create a snapshot of the database
  Watching..
  以上代表启动成功。
  1. 在项目中安装json-server yarn add json-server -D

  2. 在项目根目录中创建文件夹 json_server_mock 并且在文件夹中创建文件db.json

  3. 然后在package.json 的script 对象下面 添加"json-server": "json-server json_server_mock/db.json --watch"

  4. 然后在项目中启动 npm run json-server

如图所示: image.png 8. 在db.json 中新增json数据 。

raycast-untitled.png

9.调用接口

raycast-untitled (1).png

raycast-untitled (2).png

11.查看是否修改成功

image.png

大功告成,可以不用看后台脸色写代码了。