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