vue.js - 无限滚动到下一页
问题描述
我正在尝试使用 vue、vue-infinite-scroll 和看板进行无限滚动以更改页面。这里的问题是当滚动条到达内容的末尾时将所有其他页面一起返回,这是我的代码
methods: {
scrollLoad(status) {
this.busy = true;
const infiniteScroll = $(".drag-column-" + status);
infiniteScroll.on("scroll", () => {
// detect end of div scroll
if (
infiniteScroll[0].scrollTop +
infiniteScroll[0].clientHeight >=
infiniteScroll[0].scrollHeight - 4
) {
this.current_page ++;
axios.get(URL + '?page='+this.current_page)
.then(res => {
this.blocks.push(res.data)
this.busy = false;
}
.catch(err => {
console.log(err)
})
)
}
});
},
}
<kanban-board :stages="stages" :blocks="blocksClone" @update-block="updateBlock" :config="config">
<div v-for="(block, index) in blocks" :slot="block.id" :key="block.title" v-infinite-scroll="scrollLoad(block.status)" infinite-scroll-disabled="busy" infinite-scroll-distance="20">
<div>{{block.name}}</div>
</div>
</kanban-board>
解决方案
我这样解决了我的问题:
methods: {
scrollLoad(status) {
this.busy = true;
const infiniteScroll = $(".drag-column-" + status);
infiniteScroll.on("scroll", () => {
// detect end of div scroll
if (
infiniteScroll[0].scrollTop +
infiniteScroll[0].clientHeight >=
infiniteScroll[0].scrollHeight - 4
) {
this.current_page ++;
axios.get(URL + '?page='+this.current_page)
.then(res => {
this.blocks.push(res.data)
this.busy = false;
this.current_page = this.res.meta.current_page
}
.catch(err => {
console.log(err)
})
)
}
});
},
}
推荐阅读
- groovy - 有没有办法配置允许哪些不安全的 Groovy 操作?
- plasticscm - Plastic Cloud 版本中是否有持续集成的方法?
- python - 在 aws ElasticBean Stalk 服务器上使用 os.getcwd() 读取文件时出现问题
- json - 如何在flutter中解析复杂的json数据并分配给模型?
- swift - swift导航控制器需要不对称
- ruby-on-rails - 使用 up/down 来添加和更新现有记录的 rails 迁移
- java - int 在嵌套循环中更改值
- r - 如何在 R 中从我的桌面读取压缩文件夹
- json - 只需要从 Firebase 实时数据库中获取“carname”,但需要获取整个列表
- c++ - 改变在 C++ 中声明变量的方式