vue 实现滚动到底部翻页效果(pc端)
pc端vue滚动到底部翻页效果,具体内容如下所示:
html:
【{{item.code||item.name}}】 {{item.name}}
js:
先写滚动事件
handleScroll(){
letscrollTop=this.$refs.scrollTopList.scrollTop,
clientHeight=this.$refs.scrollTopList.clientHeight,
scrollHeight=this.$refs.scrollTopList.scrollHeight,
height=50;//根据项目实际定义
if(scrollTop+clientHeight>=scrollHeight-height){
if(this.pageSize>this.total){
returnfalse
}else{
this.pageSize=this.pageSize+10//显示条数新增
this.getpageList()//请求列表list接口方法
}
}else{
returnfalse
}
},
method中写节流函数
throttle(func,wait){
letlastTime=null
lettimeout
return()=>{
letcontext=this;
letnow=newDate();
letarg=arguments;
if(now-lastTime-wait>0){
if(timeout){
clearTimeout(timeout)
timeout=null
}
func.apply(context,arg)
lastTime=now
}elseif(!timeout){
timeout=setTimeout(()=>{
func.apply(context,arg)
},wait)
}
}
},
mounted中调用
mounted(){
this.$refs.scrollTopList.addEventListener("scroll",this.throttle(this.handleScroll,500),true)
},
//-------------------------------------------------------------------------------------------第二种写法
html:
添加滚动事件
{{item.code!=null?item.code:"/"}} {{deviceTip}}