波斯汪
相关代码// 监听滚动条new Vue({ beforeMount: function() { // 监听scroll事件 window.addEventListener('scroll', this.handleScroll) }, beforeDestroy () { window.removeEventListener('scroll', this.handleScroll) }, data: {}, mothods: { handleScroll: function() { // handle you scroll event // 最大的页面Y方向offset 加上 窗口的高度 等于 文档的高度 // max(window.pageYOffset) + window.innerHeight === document.documentElement.scrollHeight if (window.pageYOffset + window.innerHeight >= document.documentElement.scrollHeight) { // 处理上拉加载事件 放在这里 // 获取服务端数据方法 // 如果想使用预加载数据,即,即将滑动到底部时候就加载数据 // window.pageYOffset + window.innerHeight >= document.documentElement.scrollHeight - 20 } } }})