美文网首页Vue+html
vue.js window.removeEventListen

vue.js window.removeEventListen

作者: butterflyer | 来源:发表于2018-07-24 17:46 被阅读1389次

有个小坑记录下,想要移除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;
            },

ios自习室欢迎进入,一起学习一起进步。

IMG_7291.JPG

相关文章

网友评论

    本文标题:vue.js window.removeEventListen

    本文链接:https://www.haomeiwen.com/subject/vveymftx.html