下面的代碼中在componentDidMount監(jiān)聽(tīng)滾動(dòng)事件是可以的,可是躺我跳到另一個(gè)頁(yè)面的時(shí)候并有走componentWillUnmount中的移除監(jiān)聽(tīng)事件。有什么方法能解決嗎??componentDidMount(){//監(jiān)聽(tīng)滾動(dòng)window.addEventListener('scroll',()=>{console.log('滾動(dòng)');constscrollTop=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;constheader=document.body.querySelector('.headerStyle')if(scrollTop>100){header.style.backgroundColor='#FF8949'}elseif(scrollTop{console.log('移除');constscrollTop=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0;constheader=document.body.querySelector('.headerStyle')if(scrollTop>100){header.style.backgroundColor='rgba(247,247,247,1)'}elseif(scrollTop
react中怎么移除監(jiān)聽(tīng)的滾動(dòng)事件
慕田峪9158850
2019-05-09 08:20:32