在Vue中监听页面滚动事件,可以通过在mounted钩子函数中添加滚动事件监听器。具体步骤如下:
在Vue组件中添加一个监听滚动事件的方法,例如handleScroll。
在mounted钩子函数中,使用addEventListener方法监听滚动事件,并传入滚动事件处理函数handleScroll。
在beforeDestroy钩子函数中,使用removeEventListener方法移除滚动事件监听器。
示例代码如下:
<template><div><!-- 页面内容 --></div></template><script>export default {mounted() {window.addEventListener('scroll', this.handleScroll);},beforeDestroy() {window.removeEventListener('scroll', this.handleScroll);},methods: {handleScroll() {// 处理滚动事件}}}</script>在handleScroll方法中,你可以编写你需要执行的滚动事件处理逻辑。

