Files
Web_Template_Vue3_Dev/AI-Coding/03-Mock-System.md

24 lines
871 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 03. Mock 系统(开发联调与脱网演示)
## 挂载方式
- `vue.config.js``devServer.setupMiddlewares = require('./mock')`
- `mock/index.js`
- 将路由集合转换为 express 形式
- 使用 `mockjs` 返回数据
- 监听 `mock/` 变更并热更新(`chokidar`
## 路由定义约定(供 AI 生成/扩展)
`mock/controller/*.js` 中,每个路由对象通常包含:
- `url`:不含 `baseURL` 前缀的路径(中间件会自动拼上 `baseURL`
- `type``get` / `post` / ...
- `response(req, res)`:返回对象或函数
## AI 新增业务 API 的推荐动作
1) 在 `src/api/<domain>.ts` 新增函数(调用 `request({ url, method })`
2) 在 `mock/controller/<domain>.js` 新增对应 mock 路由,路径保持一致
3) 在模块规格中补充接口契约(建议写到 `openspec-lite/modules/<domain>.yaml`