在handleScroll()方法中添加console.log(‘scroll’);发现回到首页,其实 window.addEventListener(‘scroll’, this.doScroll)事件并没有被销毁,滚动时,控制台仍能输出‘scroll’,vue官网上也并没有找到unmounted()函数。使用destroyed进行解绑销毁
methods: {handleScroll() {console.log('scroll')const top = document.documentElement.scrollTopif (top > 60) {let opacity = top / 140opacity = opacity > 1 ? 1 : opacitythis.opacityStyle = {opacity}this.showAbs = false}else {this.showAbs = true}}},mounted() {window.addEventListener('scroll', this.handleScroll)},destroyed() {window.removeEventListener('scroll', this.handleScroll)}