Mock 数据

41 阅读1分钟

1. Mock 数据的方式

14.png

2. json-server 实现 Mock 数据

  1. 项目中安装json-server npm i -D json-server
  2. 准备一个json文件
  3. 添加启动命令
//package.json
  "scripts": {
    "start": "craco start",
    "build": "craco build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "server": "json-server ./server/data.json --port 8888"
  },
  1. 执行我们自己添加的命令即可开启mock服务

image.png

image.png