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;
            },
原文地址:https://www.cnblogs.com/style-hyh/p/10174412.html