created () {
var that = this;
window.addEventListener('scroll',this.scroll,true)
console.log(this.$router)
this.getList();
},
destroyed () {
window.removeEventListener('scroll', this.scroll,true)
},
methods: {
scroll() {
var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;
var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
var scrollHeight = document.body.scrollHeight;
console.log(scrollTop+windowHeight,scrollHeight)
if(scrollTop+windowHeight>=scrollHeight){ //测试浏览器有的时候相加 会出现小数点 这里用 >= 不用 ==
if(this.page <= this.totalPage) {
this.getList();
}
}
}
}
getList () {
this.page++;
if (this.isLoading) {
return;
}
if (this.page > this.totalPage) {
this.nomore = true;
return;
}
this.isLoading = true;
OrderService.getList(this, this.orderStatus, this.page, (data) => {
this.isLoading = false;
this.totalPage = data.data.totalPage;
for (var i = 0; i < data.data.datas.length; i++) {
this.list.push(data.data.datas[i]);
}
});
},