<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
#table_content {
width: 80%;
height: 300px;
border: 1px solid #ccc;
overflow-y: scroll;
}
</style>
</head>
<body>
<div id="app">
<div id="table_content" @scroll="scroll">
<table id="table" border="1">
<tr v-for="item in list">
<td>{{item.id}}</td>
<td>{{item.title}}</td>
</tr>
</table>
</div>
</div>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
list: [],//列表數(shù)據(jù)
page: 1,//分頁,默認為第一頁
status: 1,//狀態(tài),為0不在請求數(shù)據(jù)
},
methods: {
getData() {
var that = this;
if(that.status==0){
console.log("沒有更多啦");
return false;
}
$.ajax({
url: "http://jsonplaceholder.typicode.com/todos",
data: {
_page: that.page,
_limit: 15
},
success: function(result) {
if (that.page == 1) {
that.list = result;
setTimeout(function(){
that.scroll();
});
} else {
if (result.length > 0) {
that.list = that.list.concat(result);
setTimeout(function(){
that.scroll();
});
} else {
that.status = 0;//沒有數(shù)據(jù)將狀態(tài)改為0
console.log("沒有更多啦");
}
}
}
});
},
scroll() {
var that = this;
var scrollHeight = document.getElementById("table_content").scrollHeight;
var scrollTop = document.getElementById("table_content").scrollTop;
var clientHeight = document.getElementById("table_content").clientHeight;
console.log(scrollHeight+"----"+scrollTop+"----"+clientHeight);
if (scrollHeight - clientHeight == scrollTop) {
that.page++;
that.getData();
}
}
}
})
// 首次請求數(shù)據(jù)
vm.getData();
</script>
</html>
js 滾動條滾動到底部時,觸發(fā)加載數(shù)據(jù)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關(guān)閱讀更多精彩內(nèi)容
- 現(xiàn)象:滾動條在底部觸發(fā)兩次加載事件 當滾動條在底部顯示時 滾動分頁代碼實現(xiàn) 火狐bug:當滾動條顯示在頁面底部時,...
- 項目中,因為數(shù)據(jù)量過大,為提高頁面性能,采用頁面滑動 滾動條到底部的時候再進行數(shù)據(jù)請求分頁,這邊給大給個核心,結(jié)合...
- 過了初七不是年,今天回歸工作崗位的你,假期已經(jīng)清零了。在這短短的假期間,你和家人的感情是否經(jīng)歷了期待,熱情,平淡到...