//1.在main.js里注册
Vue.directive('loadmore', {
bind(el, binding) {
const selectWrap = el.querySelector('.el-table__body-wrapper')
selectWrap.addEventListener('scroll', function() {
let sign = 0
const scrollDistance = this.scrollHeight - this.scrollTop - this.clientHeight
if (scrollDistance <= sign) {
binding.value()
}
})
}
})
//2.在el-table组件中,使用自定义的事件:v-loadmore=“loadMore”
//3.在methods中调用loadMore
loadMore() {
if(this.aq == false){//是否已经全部加载
return
}
if(this.page == 1){//首次加载页码加一
this.page++
}
this.$axios({
method:'get',
url:数据接口地址,
params:{
page:this.page,
limit:this.limit
}
}).then(res=>{
if(res.data.length > 0){//有数据
this.page++ //页码加一,下次查询
res.data.forEach(res => {
this.tableData.push(res)//push到表格数据集合
});
}else{
this.aq = false //没有数据了
}
})
},
posted @
2022-08-25 11:53
醉温柔
阅读(
554)
评论()
编辑
收藏
举报