vue上滑加载更多,让滚轮在原来的位置

vue上滑加载更多,让滚轮在原来的位置

在这里插入图片描述

<div
    class="sessionArea"
    @scroll="onScroll"
    ref="loadMoreMsg"
></div>
//moreHistoryUrl是表示加载更多历史的url,showMore表示是展示加载中(true)
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;
    }
},
//conversation是历史消息列表
//更多历史消息
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 () {
                    //这里的-50是表示加载中这几个字div的高度(你是多少减多少)
                    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);
            }
       })
},
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值