vue.js window.removeEventListener 移除


vue项目中的小坑记录下,想要移除window的addEventListener,需要把后面的function挂在到this上,
removeEventListener 和 addEventListener 中对应的参数要一致。

beforeDestroy() { //在组件生命周期结束的时候销毁。
            window.removeEventListener('scroll', this.scrollhandle);
        },
        methods: {
            listenerAction() { 
                window.addEventListener('scroll', this.scrollhandle);
            },
            scrollhandle(event) {
                var scrollY = event.path[1].scrollY;
            },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM