Is your feature request related to a problem? Please describe.
In some applications, such as a messaging apps chat box, one would like to scroll to the bottom of a QScrollArea on a new message.
Describe the solution you'd like
An API method for QScrollArea to scroll to the bottom.
Describe alternatives you've considered
this.$refs.chatScroll.setScrollPosition(this.$refs.chatScroll.$el.scrollHeight, 1)
setScrollPosition is such a method but the above doesn't seem to scroll to bottom correctly all the time.
const scrollArea = this.$refs.chatScroll;
const scrollTarget = scrollArea.getScrollTarget();
const duration = 300; // ms - use 0 to instant scroll
scrollArea.setScrollPosition(scrollTarget.scrollHeight, duration);
data(){
return {
scrollsize: 0;
}
},
watch:{ // 监控滚动条的变化
scrollsize: function(val){
this.$refs.chatArea.setScrollPosition(val-500,100); //设置到底部,500是我自己设置的聊天区域高度
}
},
scrollinfo(info){
const size = info.verticalSize;
this.scrollsize = size;
}
Most helpful comment
https://codepen.io/pdanpdan/pen/yLyQdOz?editors=1010