要先在页面有个滚动到底部的执行方法(我这里起名叫onPageScroll)<\/h2>内部可以做一些处理,我这里是加了一个滚动到底部的条件<\/blockquote>export const scrollEvent = {\n methods: {\n onScroll(){\n \/\/ 变量scrollTop是滚动条滚动时,距离顶部的距离\n var scrollTop =\n document.documentElement.scrollTop ||\n document.body.scrollTop;\n \/\/ 变量windowHeight是可视区的高度\n var windowHeight =\n document.documentElement.clientHeight ||\n document.body.clientHeight;\n \/\/ 变量scrollHeight是滚动条的总高度\n var scrollHeight =\n document.documentElement.scrollHeight ||\n document.body.scrollHeight;\n \/\/ 滚动条到底部的条件\n if (scrollTop + windowHeight == scrollHeight) {\n \/\/ 滚动到底部 调用页面方法\n this.onPageScroll && this.onPageScroll();\n }\n }\n },\n mounted() {\n window.addEventListener('scroll', this.onScroll)\n },\n destroyed() {\n window.removeEventListener('scroll', this.onScroll, false);\n },\n}\n<\/pre>
export const scrollEvent = {\n methods: {\n onScroll(){\n \/\/ 变量scrollTop是滚动条滚动时,距离顶部的距离\n var scrollTop =\n document.documentElement.scrollTop ||\n document.body.scrollTop;\n \/\/ 变量windowHeight是可视区的高度\n var windowHeight =\n document.documentElement.clientHeight ||\n document.body.clientHeight;\n \/\/ 变量scrollHeight是滚动条的总高度\n var scrollHeight =\n document.documentElement.scrollHeight ||\n document.body.scrollHeight;\n \/\/ 滚动条到底部的条件\n if (scrollTop + windowHeight == scrollHeight) {\n \/\/ 滚动到底部 调用页面方法\n this.onPageScroll && this.onPageScroll();\n }\n }\n },\n mounted() {\n window.addEventListener('scroll', this.onScroll)\n },\n destroyed() {\n window.removeEventListener('scroll', this.onScroll, false);\n },\n}\n<\/pre>