1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > vue 中通过监测滚动条加载数据(懒加载数据)

vue 中通过监测滚动条加载数据(懒加载数据)

时间:2018-12-01 18:56:34

相关推荐

vue 中通过监测滚动条加载数据(懒加载数据)

vue 中监测滚动条加载数据(懒加载数据)

methods: {titleAlert(title) {console.log(title);alert(title)},// 获取滚动条当前的位置getScrollTop() {let scrollTop = 0if (document.documentElement && document.documentElement.scrollTop) {scrollTop = document.documentElement.scrollTop} else if (document.body) {scrollTop = document.body.scrollTop}return scrollTop},// 获取当前可视范围的高度getClientHeight() {let clientHeight = 0if (document.body.clientHeight && document.documentElement.clientHeight) {clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight)} else {clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight)}return clientHeight},// 获取文档完整的高度getScrollHeight() {return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)},// 滚动事件触发下拉加载onScroll() {if (this.getScrollHeight() - this.getClientHeight() - this.getScrollTop() <= 0) {if (this.status <= 5) {this.status++;// 调用请求函数this.axios.get('/rock/book/recommend?start=128&count=16&user_type=3&top_count=0&filter_count=6').then(data => {this.data = this.data.concat(data.data.items)// console.log(data.data.items);console.log(this.data)});} else {alert('没有更多内容了!!!');}}},},

mounted钩子函数监听滚动事件

mounted() {this.$nextTick(function () {window.addEventListener('scroll', this.onScroll);console.log(this.data)})},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。