问题描述
局部滚动条往下滑动时触发下拉刷新
解决方案:
提示:这里填写该问题的具体解决方案: van-pull-refresh 有 disabled 属性,可以控制是否禁用下拉刷新,通过监听touchmove 和touchend 事件获取局部滚动高度scrollTop ,然后监听滚动高度scrollTop ,滚动高度大于0时将van-pull-refresh 的 disabled 属性设置为true,禁用下拉刷新,当滚动高度scrollTop 回到0的时候再将 disabled 属性设置为false.
<template>
<van-pull-refresh
v-model="refreshing"
:disabled="isRefreshDisable"
@refresh="onRefresh"
>
<van-list
v-if="worlOrderList.length >= 0"
v-model="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
<div v-for="(item, index) in worlOrderList" :key="index">
{{ item.name }}
</div>
</van-list>
<div v-else class="no-data">
暂无数据
</div>
</van-pull-refresh>
</template>
<script>
import Vue from 'vue'
import { Toast } from 'vant'
Vue.use(Toast)
export default {
components: {
},
data() {
return {
worlOrderList: [
{ name: 111 },
{ name: 222 },
{ name: 333 },
{ name: 444 }
],
refreshing: false,
loading: false,
finished: false,
total: 0,
queryList: { current: 1, size: 10 },
scrollTop: 0,
isRefreshDisable: false
}
},
watch: {
scrollTop(newval) {
if (newval > 0) {
this.isRefreshDisable = true
} else {
this.isRefreshDisable = false
}
}
},
created() {},
mounted() {
this.$nextTick(() => {
const vantList = document.querySelector('.van-list')
this.resolveConflict(vantList)
})
},
methods: {
resolveConflict(val) {
const vantList = val
vantList.addEventListener('touchmove', () => {
this.scrollTop = vantList.scrollTop
})
vantList.addEventListener('touchend', () => {
this.scrollTop = vantList.scrollTop
})
},
}
}
</script>
|