14. Vue Project-Unbinding of global events (very important!!!)

Question: The
previous article used window.addEventListener('scroll', this.handleScroll) in the fade-out effect made in the Header.vue component of the detail page ,
but the global event was not unbound in time. The code causes a lot of bugs.
It can also be executed when you go to the homepage and slide, this is because the window is bound to the global object, not bound in the component
Insert picture description here

Insert picture description here
solve:

When we use keep-alive on the component, there will be an additional deactivated() life cycle hook function: executed when the page is about to be hidden or is about to be replaced with a new page

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45811256/article/details/109479548