1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > nuxt.js/vue监听页面滚动到底部

nuxt.js/vue监听页面滚动到底部

时间:2022-09-27 12:08:11

相关推荐

nuxt.js/vue监听页面滚动到底部

环境: nuxt.js/vue

实现

mounted() {let that = this;this.$nextTick(() => {// this.initScroll()window.onscroll = function () {//变量scrollTop是滚动条滚动时,距离顶部的距离var scrollTop =document.documentElement.scrollTop || document.body.scrollTop;//变量windowHeight是可视区的高度var windowHeight =document.documentElement.clientHeight || document.body.clientHeight;//变量scrollHeight是滚动条的总高度var scrollHeight =document.documentElement.scrollHeight || document.body.scrollHeight;//滚动条到底部的条件if (scrollTop + windowHeight == scrollHeight) {//写后台加载数据的函数 一定要用thatthat.page = that.page + 1;that.getData();}};});},

其中,this 一定要复制给 that, 后续都用that 进行调用变量与函数。

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