后端接口总是很慢怎么办?mockjs 不能增删改查怎么办?
答:json-server git地址
步骤:
- 全局安装json-server npm i json-server -g
- 在项目中创建db.json
- 启动服务 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..
以上代表启动成功。
-
在项目中安装json-server yarn add json-server -D
-
在项目根目录中创建文件夹 json_server_mock 并且在文件夹中创建文件db.json
-
然后在package.json 的script 对象下面 添加"json-server": "json-server json_server_mock/db.json --watch"
-
然后在项目中启动 npm run json-server
如图所示:
8. 在db.json 中新增json数据 。
9.调用接口
11.查看是否修改成功
大功告成,可以不用看后台脸色写代码了。