react 实现聊天界面,发送消息自动到底部

<div style={{ float:"left", clear: "both" }}
                         ref={(el) => { this.messagesEnd = el; }}>
</div>      
  scrollToBottom = () => {
    this.messagesEnd.scrollIntoView({ behavior: "auto" });
  }
  componentDidUpdate(prevProps, prevState, snapshot) {
    const { message } = this.state;
    this.scrollToBottom();

  }
  componentDidMount() {
      this.scrollToBottom();
}

 

posted @ 2023-06-02 09:25  WrYcF  阅读(185)  评论(0编辑  收藏  举报
Live2D