监听页面滚动:
mounted() {
window.addEventListener('scroll', this.handleScroll)
},
methods: {
/** 处理页面滚动*/
handleScroll() {
let scrollTop = window.pageYOffset ||document.documentElement.scrollTop ||document.body.scrollTop;
console.log(scrollTop)
},
}
监听页面高度宽度变化:
mounted() {
window.addEventListener("resize", this.handleWidth);
},
methods: {
/** 处理页面宽度变化*/
handleWidth(){
console.log(window.innerWidth)
}
},