在做消息的项目,当有新消息的时候让新消息出现在最底部,此时的box用的是overflow:auto

注意:vue项目需要注意在dom结构渲染完再进行操作

    <div class="mains" ref="chatContent">
        <Dialog :text="text"/>
    </div>
    mounted() {
        this.scrollToBottom()
    },

    updated(){
        this.scrollToBottom()
    },

    methods: {
        scrollToBottom() {
            this.$nextTick(() =>{
                this.$refs.chatContent.scrollTop = this.$refs.chatContent.scrollHeight;
            })
        }   
    }

参考博客:https://blog.csdn.net/qq_14993375/article/details/79336232?utm_source=blogxgwz1
参考博客:https://blog.csdn.net/qq_40557812/article/details/85051011

相关文章:

  • 2021-12-12
  • 2021-11-29
  • 2021-12-09
  • 2022-12-23
  • 2021-12-12
  • 2021-11-28
猜你喜欢
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-01-02
相关资源
相似解决方案