docs: 更新known-patterns.json - 增加API嵌套结构问题说明

- pat-002: 明确说明所有列表API都有相同的嵌套结构问题
- applications: 5次重复发生
This commit is contained in:
chiguyong 2026-03-22 01:42:16 +08:00
parent e0a228188a
commit 2d0f9bf5e0
1 changed files with 9 additions and 8 deletions

View File

@ -18,17 +18,18 @@
},
"pat-002": {
"name": "Axios响应数据嵌套结构",
"source": "implementation_review",
"source": "user_feedback",
"confidence": 0.95,
"applications": 1,
"applications": 5,
"created": "2026-03-22",
"category": "frontend",
"pattern": "API响应是{code, message, data{...}}嵌套结构直接访问res.data.token是undefined",
"problem": "登录成功后token存储为undefined导致isLoggedIn返回false",
"solution": "使用res.data.data获取实际的登录数据",
"pattern": "后端API响应统一格式为{code,message,data{}}前端直接访问res.data导致数据为undefined",
"problem": "登录、用户、角色、权限等页面fetch数据时res.data是ApiResponse而非实际数据",
"solution": "使用res.data.data获取实际的列表/用户数据",
"quality_rules": [
"登录数据在res.data.data中不是在res.data中",
"访问嵌套数据前先console.log打印确认结构"
"所有API调用后赋值给ref时使用 res.data.data",
"示例: users.value = res.data.data || []",
"不仅是登录API所有列表查询API都有相同的嵌套结构"
]
},
"pat-003": {
@ -50,7 +51,7 @@
"name": "Git提交纪律",
"source": "user_feedback",
"confidence": 0.95,
"applications": 3,
"applications": 5,
"created": "2026-03-22",
"category": "workflow",
"pattern": "代码修改后未提交到Gitnpm install或操作导致工作目录恢复到旧状态",