Vue中实现聊天窗口overflow:auto自动滚动到底部,实现显示当前最新聊天消息

在做消息的项目,当有新消息的时候让新消息出现在最底部,此时的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

今天你学习了吗!!!
原文地址:https://www.cnblogs.com/nayek/p/12011415.html