data () {
return {
scrolled: false
}
},
ready () {
window.addEventListener('scroll', this.handleScroll);
},
methods:{
handleScroll () {
this.scrolled = window.scrollY;
console.log(this.scrolled)
},
},
destroyed () {
window.removeEventListener('scroll', this.handleScroll)
},
created: function () {
window.addEventListener('scroll', this.handleScroll)
}
Vue 添加滚动监听
本文系作者 @坚果大叔 原创发布在 卖坚果的怪叔叔。未经许可,禁止转载。