mounted(){
window.addEventListener('scroll', this.load)
}
beforeDestroy(){
window.removeEventListener('scroll', this.load, false);
},
methods:{
load(){
//do something
}
}
最新还有一种方式,也能写的更加优雅,就是使用$on('hook:生命周期'),代码如下:
mounted(){
window.addEventListener('scroll', this.load);
this.$on("hook:beforeDestroy", () => {
window.removeEventListener('scroll', this.load);
})
}