Javascript 滚动至消息末尾

Javascript 滚动至消息末尾,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我已经使用view构建了一个messenger系统。最新消息从下至上开始。单击要查看的对话时,我希望在axios加载所有消息后自动滚动到对话底部 对话消息组件 methods: { getOldMessages(conversation_id){ setTimeout(function() { axios({ method: 'get', url: this.url, }).then(funct

我已经使用view构建了一个messenger系统。最新消息从下至上开始。单击要查看的对话时,我希望在axios加载所有消息后自动滚动到对话底部

对话消息组件

methods: {
  getOldMessages(conversation_id){

        setTimeout(function() {
        axios({
            method: 'get',
            url: this.url,
        }).then(function(response) {
            //console.log(response.data);

            this.messages = response.data;

            this.scrollToEnd();

        }.bind(this))
        .catch(function(error) {

        });
    }.bind(this))
  },
  scrollToEnd: function() {     
    var container = this.$el.querySelector(".single-conversation");
    container.scrollTop = container.scrollHeight;
  },
}

您试图在呈现
消息之前滚动到消息视图的末尾。在滚动之前,您应该等到:

this.messages = response.data;
this.$nextTick(() => this.scrollToEnd())