赞
踩
<van-pull-refresh v-model="isLoading" @refresh="onRefresh" :disabled="refreshDisabled" >
<van-pull-refresh>
refreshDisabled:false,
scrollTop:0
在mounted钩子函数中获取元素滚动值,值有滚动值大于0时才触发下拉事件:
<div class="list_data" ref="tableScorll">//此绑定元素为滚动元素,也就是设置overflow:auto;的元素
mounted(){
let tableScorll = this.$refs.tableScorll;
tableScorll .addEventListener('scroll',()=>{
this.scrollTop = tableScorll.scrollTop//data中定义scrollTop为0
});
},
watch:{
scrollTop(newVal){
if(newVal<=0){
this.refreshDisabled = false
}else{
this.refreshDisabled = true
}
}
}
到这就可以解决了冲突问题,但是如果说列表加了空数据组件的话,就需要用v-show来切换,不然mounted钩子函数中ref获取不到dom元素
<van-pull-refresh v-model="isLoading" @refresh="onRefresh" :disabled="refreshDisabled" >
<van-empty description="描述文字" v-if = "listData.length == 0"/>
<div class="list_data" ref="tableScorll" v-show = "listData.length !== 0">
//内容
</div>
</van-pull-refresh>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。