2022-06-08 react window.addEventListener 无效

代码:

    componentDidMount() {
        window.addEventListener('scroll', this.handleScroll);
    }
      handleScroll = (e) => {
          console.log(e);
    }

解决方案:

window.addEventListener('scroll', this.handleScroll)添加一个true,即:
window.addEventListener('scroll', this.handleScroll, true);
 
posted @ 2022-06-08 13:58  叶乘风  阅读(776)  评论(0编辑  收藏  举报