异常 did you register the component correctly? For recursive components, make sure to provide the “nam

1。vue项目使用抽屉组件时候报错did you register the component correctly? For recursive components, make sure to provide the “name”

在这里插入图片描述
百度进行搜索,发现很多博主的答案都不一样,根据每一个进行排查,发现自己都不存在该问题,于是找了半天,发现是自己的import语句加了{},下面总结一下几位博主和自己的错误原因:
1.1:在main.js中没有对组件进行正确的引用及注册:
在这里插入图片描述
1.2 在引入的时候,components单词拼错:
在这里插入图片描述
1.3在引入的时候import {。。},加多大括号(我犯错的地方)
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在React中,如果你在注册组件时遇到问题,特别是对于递归组件(recursive component),可能是因为没有正确地提供`name`属性或`forwardRef`处理。这里是一些关键点: 1. **命名递归组件**:当你定义一个递归组件时,需要为每个层级的组件分配一个唯一的名称,以防名称冲突。例如,使用`React.memo`或`React.forwardRef`时,确保像这样使用: ```jsx const RecursiveComponent = React.forwardRef((props, ref) => { const name = useRef(props.name || 'defaultName'); // 假设props包含name属性 if (props.children && props.children.type === RecursiveComponent) { return <RecursiveComponent name={name.current + 1} ref={ref} {...props} />; } return ( <div ref={ref}> {name.current} {props.children} </div> ); }); // 注册组件时传递名称 const registeredComponent = React.memo(RecursiveComponent)({ name: 'base' }); ``` 2. **`forwardRef`的使用**:确保你在`forwardRef`中提供了正确的引用,以便在组件树中追踪实例。记得传入`ref`到子组件: ```jsx const RecursiveComponent = React.forwardRef(({ children, ...props }, ref) => { // ... return <RecursiveComponent ref={ref} {...props} />; }); ``` 3. **检查类型和条件**:递归组件应该有一个明确的结束条件,防止无限递归。确保你在组件内部有适当的终止条件,并且正确处理了`null`或`undefined`的children。 如果以上步骤都已完成,但仍然报错,相关问题可能包括:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值