其他分享
首页 > 其他分享> > 滑动加载

滑动加载

作者:互联网

html

<div
class="message-box"
data-spy="scroll"
data-target="#navbar-example"
data-offset="0"
ref="messageList"
>
    
</div>

 js

mounted() {
    // 缓存指针
    let _this = this;
    // 注册scroll事件并监听
    this.$refs.messageList.addEventListener('scroll', () => {
      _this.customEventFun()
    });
  },
  methods: {
    //methods start
    customEventFun() {
      if ((this.$refs.messageList.scrollTop + this.$refs.messageList.clientHeight) >= this.$refs.messageList.scrollHeight) {
        console.log(this.$refs.messageList.scrollTop, "滚动高度");
        console.log(this.$refs.messageList.clientHeight, "可视区域高度");
        console.log(this.$refs.messageList.scrollHeight, "内容高度");
        this.$emit("loadData")
      }
    },
}

 

标签:console,log,refs,messageList,methods,customEventFun,滑动,加载
来源: https://www.cnblogs.com/wxchun/p/16638861.html