title: mockjs
tags:
- mockjs
- mock
- js库
categories: - JavaScript
abbrlink: 25c5823c
date: 2023-02-15 23:29:31
介绍
生成随机数据,拦截 Ajax 请求
使用
import axios from "axios"; import Mock from "mockjs"; Mock.mock("http://localhost:3000/api", { "data|5": [ { "id|+1": 1, name: "@cname", "age|18-28": 1, }, ], }); axios.get("http://localhost:3000/api").then((res) => { console.log(res.data); });
输出
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2lYBFebR-1677494065470)(http://qiniu.yujing.fit/typora_img/image-20230215233230950.png)]
相关链接
- 官方文档: https://github.com/nuysoft/Mock/wiki
- 示例代码: http://mockjs.com/examples.html
- 更多博客: https://yujing.fit/