<div ref="list" @scroll="handleScroll"></div>
created()
created() {
//判断是手机端和pc端
this.device()
if(this.isPc == true){
this.clientHeight = document.documentElement.clientHeight;
window.addEventListener('scroll', this.handleScroll);
}
this.getData();
}
methods: {}
methods: {
//判断是手机端还是PC端
isMobile() {
let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag;
},
device(){
if (this.isMobile()) {
console.log("移动端");
this.isPc = false
} else {
console.log("pc端");
this.isPc = true
}
}
// 鼠标滚动加载数据
handleScroll(){
let a = this.$refs.list.getBoundingClientRect().bottom;
a = Math.ceil(a);
if (a == this.clientHeight || a-1 == this.clientHeight) {
this.page++
this.getData();
}
},
destroyed()
destroyed() {
window.removeEventListener("scroll", this.handleScroll);
},