vue2:Unknown custom element: <> - did you register the component correctly?
·
出现Unknown custom element: <> - did you register the component correctly? For recursive compon 检查以下几处
-
检查组件注册语法
- 确保使用
components: {}对象形式(非函数) - 示例错误:
components(){}或拼写为component: {} - 正确写法:
export default { components: { MyComponent // 组件注册列表 } }
- 确保使用
-
避免重复注册覆盖
- 同一组件选项中只能有一个
components: {}对象 - 错误示例:
export default { components: { CompA }, // ...其他选项 } export default { // ❌ 重复定义会覆盖前者 components: { CompB } } - 正确做法:合并所有组件到单个
components对象
- 同一组件选项中只能有一个
-
确认组件导入方式
- 默认导出:
import MyComponent from './MyComponent.vue' - 命名导出:
import { MyComponent } from './components' - 检查目标组件文件的导出方式(
export default或export const)
- 默认导出:
-
避免 ID 与组件名冲突
- 模板中
<div id="my-component">不要与组件名重复 - 错误示例:
<div id="myComponent"> <my-component /> <!-- ❌ ID与组件名冲突 --> </div> - 建议使用唯一 ID 命名(如
id="page-container")
- 模板中
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)