(亲测可用)vue新消息自动滚到底部

切慕溪水 2019-11-03

mounted () {
   this.scrollToBottom();
},

 
//每次页面渲染完之后滚动条在最底部
updated:function(){
   this.scrollToBottom();
},
 
 
 methods: {
// 
     scrollToBottom() {
     this.$nextTick(() => {
        var container = this.$el.querySelector(" 需要滚动条处于底部的容器,css类名 ");
        container.scrollTop = container.scrollHeight;
     })}
 
}
  ```

关于获取this.$el.querySelector的知识,可以参考这里:

[this.$el.querySelector](https://developer.mozilla.org/zh-CN/docs/Web/API/Element/querySelector)

相关推荐