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;
},
