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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM