2.0 KiB
2.0 KiB
常见错误速查表
Vue 3
| 错误 | 原因 | 修复 |
|---|---|---|
[Vue warn] Missing required prop |
必填 prop 未传入 | 检查父组件传参或设置默认值 |
Maximum recursive updates |
响应式数据在 watch 中循环修改 | 添加条件判断或用 watchEffect 替代 |
inject() can only be called inside setup() |
依赖注入在非 setup 中调用 | 移入 <script setup> 或 setup() 函数 |
Extraneous non-props attributes |
组件未声明 inheritAttrs: false |
添加 defineOptions({ inheritAttrs: false }) |
Component is missing template |
组件缺少 template 或 render | 检查 .vue 文件是否有 <template> |
TypeScript
| 错误 | 原因 | 修复 |
|---|---|---|
Cannot read properties of undefined |
访问未定义对象属性 | 增加空值判断或使用可选链 ?. |
Unexpected token 'export' |
运行环境与模块格式不匹配 | 检查 ESM/CJS 配置与运行命令 |
x is not a function |
导入或变量类型错误 | 检查导出方式与调用处参数 |
PHP Hyperf
| 错误 | 原因 | 修复 |
|---|---|---|
Class not found |
DI 容器未注册或命名空间错误 | 检查 namespace、运行 composer dump-autoload |
Connection pool exhausted |
连接池已满,协程等待超时 | 增大 max_connections 或减少连接占用时间 |
Coroutine context destroyed |
在协程外访问协程上下文 | 使用 Context::get() 前确保在协程环境 |
Table not found |
迁移未执行 | 运行 php bin/hyperf.php migrate |
Allowed memory exhausted |
内存泄漏或大数据未分块 | 使用 chunk() 处理大数据集 |
MySQL
| 错误 | 原因 | 修复 |
|---|---|---|
| Duplicate entry (1062) | 插入重复唯一键数据 | 用 INSERT ... ON DUPLICATE KEY UPDATE 或先查询 |
| Lock wait timeout (1205) | 事务死锁或长事务 | 缩短事务范围,添加合适索引 |
| Too many connections (1040) | 连接数超限 | 检查连接池配置,增大 max_connections |