上次在Header.vue中写了一个:

activated () {
    window.addEventListener('scroll', this.handleScroll)
  },

这个是对全局的 window 对象,所以会出现问题,不仅对这个组件,也对全局的组件都造成了影响。

解决办法:

// 页面即将被隐藏 或者说 页面即将被替换成新的页面时,deactivated会被执行
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  },

也就是页面展示的时候去绑定 scroll 事件,而页面被隐藏的时候,再去对 scroll 这个全局事件进行一个解绑。

然后再提交下代码:

git add .
git commit -m "对全局事件解绑"
git push

git checkout detail-header
git merge master
git push

 

相关文章:

  • 2021-08-03
  • 2021-12-11
  • 2021-12-12
  • 2021-06-18
  • 2021-12-20
  • 2021-12-17
  • 2021-06-13
  • 2021-08-21
猜你喜欢
  • 2021-09-30
  • 2021-10-19
  • 2021-06-28
  • 2021-09-05
  • 2021-10-16
  • 2022-02-28
  • 2022-01-13
相关资源
相似解决方案