We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
接口模拟几乎已经成为每个前端的必备技能。可否集成一下?推荐 mockm :
npm i mockm -D npx mockm --template
/** * @see: https://www.hongqiye.com/doc/mockm/config/option.html * @type {import('mockm/@types/config').Config} */ module.exports = util => { return { // 代理后端的接口, 如果没有可以不填 proxy: { // 根结点 '/': `https://httpbin.org/`, // 接口转发 '/get': `https://www.httpbin.org/ip`, // 修改响应体中的 json '/anything/mid': [`headers.Host`, `xxxxxx`], // 使用函数修改响应体 '/anything/proxy/fn':[({req, json}) => { return (json.method + req.method).toLowerCase() // getget }], }, // 自己编写的接口 api: { // 当为基本数据类型时, 直接返回数据, 这个接口返回 {"msg":"ok"} '/api/1': {msg: `ok`}, // 也可以像 express 一样返回数据 '/api/2' (req, res) { res.send({msg: `ok`}) }, // 一个只能使用 post 方法访问的接口 'post /api/3': {msg: `ok`}, // 一个 websocket 接口, 会发送收到的消息 'ws /api/4' (ws, req) { ws.on(`message`, (msg) => ws.send(msg)) }, // 一个下载文件的接口 '/file' (req, res) { res.download(__filename) }, // 获取动态的接口路径的参数 code '/status/:code' (req, res) { res.json({statusCode: req.params.code}) }, }, // 自动生成 Restful API db: { 'users': util.libObj.mockjs.mock({ 'data|15-23': [ // 随机生成 15 至 23 条数据 { 'id|+1': 1, // id 从 1 开始自增 name: `@cname`, // 随机生成中文名字 'sex|1': [`男`, `女`, `保密`], // 性别从这三个选项中随机选择一个 }, ] }).data, }, } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
接口模拟几乎已经成为每个前端的必备技能。可否集成一下?推荐 mockm :
功能: 点击查看
示例: 点击查看
The text was updated successfully, but these errors were encountered: