vue上滑加载更多,让滚轮在原来的位置
<div
class="sessionArea"
@scroll="onScroll"
ref="loadMoreMsg"
></div>
onScroll() {
var contentHeight = this.$refs.loadMoreMsg.scrollTop;
if (contentHeight < 1 && this.moreHistoryUrl != null && !this.showMore) {
this.showMore = true;
this.getMoreHistory();
} else if (this.moreHistoryUrl == null) {
this.showMore = false;
}
},
getMoreHistory() {
let that = this;
var scrollH = that.$refs.loadMoreMsg.scrollHeight;
this.axios
.get(this.moreHistoryUrl)
.then((res) => {
if (res.data.code == 200) {
let data = res.data.data.data.reverse();
this.conversation = data.concat(this.conversation);
this.moreHistoryUrl = res.data.data.next_page_url;
this.$nextTick(function () {
let diff = that.height ? scrollH - that.height : -50;
that.height = that.$refs.loadMoreMsg.scrollHeight;
that.$refs.loadMoreMsg.scrollTop = that.height - scrollH + diff;
that.showMore = false;
});
} else {
alert(res.message);
}
})
},