🚀 快速安装
复制以下命令并运行,立即安装此 Skill:
npx @anthropic-ai/skills install hyf0/vue-skills/vue-debug-guides
💡 提示:需要 Node.js 和 NPM
Vue 3 调试与错误处理指南,涵盖运行时问题、警告、异步失败和水合错误。
有关开发最佳实践和常见陷阱,请使用 vue-best-practices。
响应式
- 追踪意外的重新渲染和状态更新 → 参见 reactivity-debugging-hooks
- 因缺少 .value 访问导致 ref 值不更新 → 参见 ref-value-access
- 解构响应式对象后状态停止更新 → 参见 reactive-destructuring
- 数组、Map 或 Set 中的 ref 未被解包 → 参见 refs-in-collections-need-value
- 嵌套 ref 在模板中渲染为 [object Object] → 参见 template-ref-unwrapping-top-level
- 响应式代理的身份比较总是返回 false → 参见 reactivity-proxy-identity-hazard
- 第三方实例在被代理时出现问题 → 参见 reactivity-markraw-for-non-reactive
- 侦听器意外地每 tick 只触发一次 → 参见 reactivity-same-tick-batching
计算属性
- 计算属性的 getter 意外触发了突变或请求 → 参见 computed-no-side-effects
- 修改计算属性导致更改消失 → 参见 computed-return-value-readonly
- 在条件逻辑之后计算属性值从不更新 → 参见 computed-conditional-dependencies
- 对数组进行排序或反转会破坏原始状态 → 参见 computed-array-mutation
- 向计算属性传递参数失败 → 参见 computed-no-parameters
侦听器
- 异步操作用过时数据覆盖 → 参见 watch-async-cleanup
- 在异步回调中创建侦听器 → 参见 watch-async-creation-memory-leak
- 侦听器从未为响应式对象属性触发 → 参见 watch-reactive-property-getter
- 在 await 之后,异步 watchEffect 遗漏了依赖项 → 参见 watcheffect-async-dependency-tracking
- 在侦听器回调中读取的 DOM 是过时的 → 参见 watch-flush-timing
- 深度侦听器报告相同的旧/新值 → 参见 watch-deep-same-object-reference
- watchEffect 在模板 ref 更新之前运行 → 参见 watcheffect-flush-post-for-refs
组件
- 子组件抛出”组件未找到”错误 → 参见 local-components-not-in-descendants
- 点击监听器未在自定义组件上触发 → 参见 click-events-on-components
- 在 script setup 中父组件无法访问子组件的 ref 数据 → 参见 component-ref-requires-defineexpose
- HTML 模板解析破坏了 Vue 组件语法 → 参见 in-dom-template-parsing-caveats
- 由于命名冲突导致渲染了错误的组件 → 参见 component-naming-conflicts
- 父级样式未应用到多根组件 → 参见 multi-root-component-class-attrs
Props 与 Emits
- defineProps 中引用的变量导致错误 → 参见 prop-defineprops-scope-limitation
- 组件触发了未声明的事件导致警告 → 参见 declare-emits-for-documentation
- defineEmits 在函数或条件语句内使用 → 参见 defineEmits-must-be-top-level
- defineEmits 同时具有类型和运行时参数 → 参见 defineEmits-no-runtime-and-type-mixed
- 原生事件监听器未响应点击 → 参见 native-event-collision-with-emits
- 点击时组件事件触发了两次 → 参见 undeclared-emits-double-firing
模板
- 使用语句时出现模板编译错误 → 参见 template-expressions-restrictions
- “无法读取 undefined 的属性”运行时错误 → 参见 v-if-null-check-order
- 动态指令参数无法正常工作 → 参见 dynamic-argument-constraints
- v-else 元素始终无条件渲染 → 参见 v-else-must-follow-v-if
- 混用 v-if 与 v-for 导致优先级错误和迁移中断 → 参见 no-v-if-with-v-for
- 模板函数调用导致状态突变,引发不可预测的重新渲染错误 → 参见 template-functions-no-side-effects
- 循环中的子组件显示未定义的数据 → 参见 v-for-component-props
- 排序或反转后数组顺序发生变化 → 参见 v-for-computed-reverse-sort
- 列表项意外消失或状态交换 → 参见 v-for-key-attribute
- 使用范围迭代时出现差一错误 → 参见 v-for-range-starts-at-one
- v-show 或 v-else 在 template 元素上不起作用 → 参见 v-show-template-limitation
模板 Refs
- 当元素被条件性隐藏时,ref 变为 null → 参见 template-ref-null-with-v-if
- 循环中 ref 数组的索引与数据数组不匹配 → 参见 template-ref-v-for-order
- 重构模板 ref 名称在代码中静默失效 → 参见 use-template-ref-vue35
表单与 v-model
- 使用 v-model 时初始表单值未显示 → 参见 v-model-ignores-html-attributes
- 文本域内容更改未更新 ref → 参见 textarea-no-interpolation
- iOS 用户无法选择下拉菜单的第一个选项 → 参见 select-initial-value-ios-bug
- 父组件和子组件的值不同 → 参见 define-model-default-value-sync
- 对象属性更改未同步到父组件 → 参见 definemodel-object-mutation-no-emit
- 中文/日文输入的实时搜索/验证失效 → 参见 v-model-ime-composition
- 数字输入返回空字符串而不是零 → 参见 v-model-number-modifier-behavior
- 自定义复选框的值未在表单中提交 → 参见 checkbox-true-false-value-form-submission
事件与修饰符
- 链式使用多个事件修饰符产生意外结果 → 参见 event-modifier-order-matters
- 键盘快捷键与系统修饰键一起使用时未触发 → 参见 keyup-modifier-timing
- 键盘快捷键触发了意外的修饰键组合 → 参见 exact-modifier-for-precise-shortcuts
- 组合 passive 和 prevent 修饰符破坏了事件行为 → 参见 no-passive-with-prevent
生命周期
- 未移除的事件监听器导致内存泄漏 → 参见 cleanup-side-effects
- 组件挂载前 DOM 访问失败 → 参见 lifecycle-dom-access-timing
- 状态更改后 DOM 读取返回过时值 → 参见 dom-update-timing-nexttick
- 服务器端渲染与客户端水合不同 → 参见 lifecycle-ssr-awareness
- 异步注册的生命周期钩子从未运行 → 参见 lifecycle-hooks-synchronous-registration
插槽
- 在插槽内容中访问子组件数据返回 undefined → 参见 slot-render-scope-parent-only
- 混合使用具名插槽和作用域插槽导致编译错误 → 参见 slot-named-scoped-explicit-default
- 在原生 HTML 元素上使用 v-slot 导致编译错误 → 参见 slot-v-slot-on-components-or-templates-only
- 隐式默认插槽行为导致意外的内容放置 → 参见 slot-implicit-default-content
- 作用域插槽属性缺少预期的名称属性 → 参见 slot-name-reserved-prop
- 包装组件破坏了子插槽功能 → 参见 slot-forwarding-to-child-components
Provide/Inject
- 在异步操作后调用 provide 静默失败 → 参见 provide-inject-synchronous-setup
- 追踪提供值的来源 → 参见 provide-inject-debugging-challenges
- 当提供者更改时,注入的值未更新 → 参见 provide-inject-reactivity-not-automatic
- 多个组件共享相同的默认对象 → 参见 provide-inject-default-value-factory
属性
- 内部事件处理程序和透传事件处理程序都执行 → 参见 attrs-event-listener-merging
- 显式属性被透传值覆盖 → 参见 fallthrough-attrs-overwrite-vue3
- 属性应用于包装组件中的错误元素 → 参见 inheritattrs-false-for-wrapper-components
组合式函数
- 在 setup 上下文外部或异步调用组合式函数 → 参见 composable-call-location-restrictions
- 当输入更改时,组合式函数的响应式依赖未更新 → 参见 composable-tovalue-inside-watcheffect
- 组合式函数意外地改变了外部状态 → 参见 composable-avoid-hidden-side-effects
- 解构组合式函数的返回值意外破坏了响应性 → 参见 composable-naming-return-pattern
组合式 API
- 异步操作后生命周期钩子静默失败 → 参见 composition-api-script-setup-async-context
- 父组件 refs 无法访问暴露的属性 → 参见 define-expose-before-await
- 函数式编程模式破坏了预期的 Vue 响应式行为 → 参见 composition-api-not-functional-programming
- React Hooks 心智模型导致组合式 API 使用不正确 → 参见 composition-api-vs-react-hooks-differences
动画
- 当 DOM 节点被复用时,动画无法触发 → 参见 animation-key-for-rerender
- TransitionGroup 列表更新在负载下感觉卡顿 → 参见 animation-transitiongroup-performance
TypeScript
- 可变的 prop 默认值在组件实例之间泄漏状态 → 参见 ts-withdefaults-mutable-factory-function
- reactive() 泛型类型导致 ref 解包不匹配 → 参见 ts-reactive-no-generic-argument
- 模板 refs 在挂载前或 v-if 卸载后抛出 null 访问错误 → 参见 ts-template-ref-null-handling
- 可选的布尔 prop 表现为 false 而不是 undefined → 参见 ts-defineprops-boolean-default-false
- 导入的 defineProps 类型因无法解析或复杂的类型引用而失败 → 参见 ts-defineprops-imported-types-limitations
- 在严格的 TypeScript 设置下,未类型化的 DOM 事件处理程序失败 → 参见 ts-event-handler-explicit-typing
- 动态组件 refs 触发了响应式组件警告 → 参见 ts-shallowref-for-dynamic-components
- 联合类型的模板表达式在没有类型缩小的情况下无法通过类型检查 → 参见 ts-template-type-casting
异步组件
- 使用 defineAsyncComponent 懒加载的路由组件配置错误 → 参见 async-component-vue-router
- 加载组件时网络故障或超时 → 参见 async-component-error-handling
- 组件重新激活后模板 refs 未定义 → 参见 async-component-keepalive-ref-issue
渲染函数
- 状态更改后渲染函数输出保持不变 → 参见 rendering-render-function-return-from-setup
- 复用的 vnode 实例渲染不正确 → 参见 render-function-vnodes-must-be-unique
- 字符串组件名称作为 HTML 元素渲染 → 参见 rendering-resolve-component-for-string-names
- 访问 vnode 内部属性在 Vue 更新时失效 → 参见 render-function-avoid-internal-vnode-properties
- Vue 2 渲染函数模式在 Vue 3 中崩溃 → 参见 rendering-render-function-h-import-vue3
- 来自 h() 的插槽内容未渲染 → 参见 rendering-render-function-slots-as-functions
KeepAlive
- 嵌套的 Vue Router 路由导致子组件挂载两次 → 参见 keepalive-router-nested-double-mount
- 将 KeepAlive 与 Transition 动画结合使用时内存增长 → 参见 keepalive-transition-memory-leak
过渡
- JavaScript 过渡钩子因缺少完成回调而挂起 → 参见 transition-js-hooks-done-callback
- 对内联列表元素的移动动画失败 → 参见 transition-group-flip-inline-elements
- 列表项跳动而不是平滑动画 → 参见 transition-group-move-animation-position-absolute
- Vue 2 到 Vue 3 的 TransitionGroup 包装器更改破坏了布局 → 参见 transition-group-no-default-wrapper-vue3
- 嵌套过渡在完成前被截断 → 参见 transition-nested-duration
- 可复用的过渡包装器中作用域样式失效 → 参见 transition-reusable-scoped-style
- RouterView 过渡在首次渲染时意外动画 → 参见 transition-router-view-appear
- 混合使用 CSS 过渡和动画导致时序问题 → 参见 transition-type-when-mixed
- 在快速过渡交换期间错过了清理钩子 → 参见 transition-unmount-hook-timing
Teleport
- Teleport 目标元素在 DOM 中未找到 → 参见 teleport-target-must-exist
- Teleported 内容破坏了 SSR 水合 → 参见 teleport-ssr-hydration
- 作用域样式未应用于 Teleported 内容 → 参见 teleport-scoped-styles-limitation
Suspense
- 需要处理来自 Suspense 组件的异步错误 → 参见 suspense-no-builtin-error-handling
- 将 Suspense 与服务器端渲染一起使用 → 参见 suspense-ssr-hydration-issues
- 在 Suspense 下,异步组件的加载/错误 UI 被忽略 → 参见 async-component-suspense-control
SSR
- 服务器和客户端渲染的 HTML 不同 → 参见 ssr-hydration-mismatch-causes
- 共享的单例存储导致请求之间的用户状态泄漏 → 参见 state-ssr-cross-request-pollution
- 在通用代码路径中,仅限浏览器的应用程序编程接口使服务器渲染崩溃 → 参见 ssr-platform-specific-apis
性能
- 因为父级传递了不稳定的 props,列表子项不必要地重新渲染 → 参见 perf-props-stability-update-optimization
- 尽管值相同,计算的对象重新触发了效果 → 参见 perf-computed-object-stability
SFC (单文件组件)
- 尝试从组件 script 块中使用命名导出 → 参见 sfc-named-exports-forbidden
- 更改后模板中的变量未更新 → 参见 sfc-script-setup-reactivity
- 作用域样式未应用于子组件元素 → 参见 sfc-scoped-css-child-component-styling
- 作用域样式未应用于动态的 v-html 内容 → 参见 sfc-scoped-css-dynamic-content
- 作用域样式未应用于插槽内容 → 参见 sfc-scoped-css-slot-content
- 动态构建时 Tailwind 类缺失 → 参见 tailwind-dynamic-class-generation
- 由于名称冲突,递归组件未渲染 → 参见 self-referencing-component-name
插件
- 调试全局属性导致命名冲突的原因 → 参见 plugin-global-properties-sparingly
- 插件无法工作或 inject 返回 undefined → 参见 plugin-install-before-mount
- 插件的全局属性在基于 setup 的组件中不可用 → 参见 plugin-prefer-provide-inject-over-global-properties
- 插件类型增强错误破坏了 ComponentCustomProperties 的类型 → 参见 plugin-typescript-type-augmentation
应用程序配置
- 在 mount 调用后应用程序配置方法不起作用 → 参见 configure-app-before-mount
- 链式调用 mount() 的应用程序配置失败,因为 mount 返回组件实例 → 参见 mount-return-value
- 基于 require.context 的组件自动注册在 Vite 中失败 → 参见 dynamic-component-registration-vite
📄 原始文档
完整文档(英文):
https://skills.sh/hyf0/vue-skills/vue-debug-guides
💡 提示:点击上方链接查看 skills.sh 原始英文文档,方便对照翻译。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)