如何在 antd 步骤中滚动到顶部.反应



我正在使用antd的步骤组件。我希望每当用户转到下一步或上一步时,页面都应该滚动到顶部。我使用 window.scrollTo(0, 0( 和 window.top=0;但它不起作用。谁能帮忙我如何滚动到顶部。

previousStep = () => {
    window.scrollTo(0, 0);
    window.scrollTop = 0;
    const { currentStep } = this.state;
    this.setState({ currentStep: currentStep - 1 });
};
onstructor(props) {
    super(props)
    this.myRef = React.createRef()   // Create a ref object 
}
componentDidMount() {
  this.myRef.current.scrollTo(0, 0);
}
render() {
    return <div ref={this.myRef}></div> 
}   // attach the ref property to a dom element

最新更新