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();
}
标签:refs,Component,next,handleNext,Carousel,组件,any 来源: https://blog.csdn.net/sunzhen15896/article/details/111359711