Property ‘next‘ does not exist on type ‘Component<any, {}, any>‘问题的解决方法

场景:使用antd的Carousel组件时,自定义左右切换按钮,触发组件的next(),prev()方法时报错

错误写法:

  handleNext(){
    
    
    this.refs.img.next()
  }
  <Carousel
     dots={
    
    false}
     ref="img"
   >
	...
   </Carousel>

handleNext是我自定义的按钮的切换下一个图片方法,通过refs获取Carousel组件实例,调用Carousel组件的next()方法

报错截图:
在这里插入图片描述
Property ‘next’ does not exist on type ‘Component<any, {}, any>’

解决方案:

  handleNext(){
    
    
    (this.refs.img as any).next();
  }

猜你喜欢

转载自blog.csdn.net/sunzhen15896/article/details/111359711