场景:使用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();
}