vue 實(shí)現(xiàn)滾動(dòng)到底部翻頁(yè)效果(pc端)
pc端vue 滾動(dòng)到底部翻頁(yè) 效果,具體內(nèi)容如下所示:
html:
<div class="list" ref="scrollTopList">
<div class="listsmall" v-for="(item,index) of list" :key="index" @click="getDeviceInfo(item.id)">
<span class="state" :class="{'state1':item.status==1,'state0':item.status==0,'state2':item.status==2,'state3':item.status==3}"></span>
<span class="text textcolor">【{{item.code||item.name}}】</span>
<span class="text">{{item.name}}</span>
</div>
</div>
js:
先寫(xiě)滾動(dòng)事件
handleScroll(){
let scrollTop = this.$refs.scrollTopList.scrollTop,
clientHeight = this.$refs.scrollTopList.clientHeight,
scrollHeight = this.$refs.scrollTopList.scrollHeight,
height = 50; //根據(jù)項(xiàng)目實(shí)際定義
if(scrollTop +clientHeight >= scrollHeight - height){
if(this.pageSize > this.total){
return false
}else{
this.pageSize = this.pageSize +10 //顯示條數(shù)新增
this.getpageList() //請(qǐng)求列表list 接口方法
}
}else{
return false
}
},
method中寫(xiě)節(jié)流函數(shù)
throttle(func, wait) {
let lastTime = null
let timeout
return () => {
let context = this;
let now = new Date();
let arg = arguments;
if (now - lastTime - wait > 0) {
if (timeout) {
clearTimeout(timeout)
timeout = null
}
func.apply(context, arg)
lastTime = now
} else if (!timeout) {
timeout = setTimeout(() => {
func.apply(context, arg)
}, wait)
}
}
},
mounted中調(diào)用
mounted(){
this.$refs.scrollTopList.addEventListener("scroll",this.throttle(this.handleScroll,500),true)
},
//-------------------------------------------------------------------------------------------第二種寫(xiě)法
html:
添加滾動(dòng)事件
<div class="tablelist-box" @scroll="scrollEvent($event)">
<div
class="tablelist"
:class="{'active':listDevicesDetailIndex==index}"
v-for="(item,index) of deviceList"
:key="index"
v-if="deviceList.length !== 0"
@click="deviceDetail(item,index)"
>
<span class="tablelist-status">
<i
:class="{zx:item.status==1,lx:item.status==2, wjh:item.status==0,gj:item.status==3}"
></i>
</span>
<span class="tablelist-bg">{{item.code != null ?item.code:"/"}}</span>
</div>
<div class="list-more" v-show="!deviceListIsFinish">{{deviceTip}}</div>
<div class="list-more" v-show="deviceListIsFinish">{{deviceTip}}</div>
</div>
css:
tablelist-box{
height: //根據(jù)實(shí)際項(xiàng)目取
overflow:auto //必須 不然判斷有問(wèn)題
}
css 定義
js
寫(xiě)入滾動(dòng)事件
scrollEvent(e) {
if (e instanceof Event) {
let el = e.target;
let scrollTop = el.scrollTop;
// 獲取可視區(qū)的高度
let clientHeight = el.clientHeight;
// 獲取滾動(dòng)條的總高度
let scrollHeight = el.scrollHeight;
let height = 50;
//到底了
// console.log(this.deviceListIsLoad, this.deviceListIsFinish);
// console.log(scrollTop, clientHeight, scrollHeight);
//是否繼續(xù)加載且已完成加載
if (
scrollTop + clientHeight >= scrollHeight &&
this.deviceListIsLoad &&
!this.deviceListIsFinish
) {
// 把距離頂部的距離加上可視區(qū)域的高度 等于或者大于滾動(dòng)條的總高度就是到達(dá)底部
this.deviceListIsLoad = true;
console.log("到底了");
setTimeout(() => {
this._deviceListPage();
}, 1000);
}
}
請(qǐng)求列表的處理
_deviceListPage() {
let params = {
pageSize: this.devicePageSize,
pageNum: this.devicePageNum,
kw: "", //查詢條件(通配查詢條件)
type: this.deviceType, //設(shè)備類型(下拉)2.1.6接口獲取
code: this.deviceCode, //設(shè)備編號(hào)
areaId: this.deviceareaId, //位置區(qū)域
status: this.deviceStatus, //狀態(tài) 1:在線(正常),0:未激活,2已離線,3.告警
imei: "" //imei編號(hào)
};
deviceListPage(params).then(res => {
if (res.code == 200) {
this.devicePageTotal = res.body.total;
this.devicePageSize = res.body.pageSize;
this.devicePageNum = res.body.pageNum;
this.devicePageTotalPages = parseInt(
(this.devicePageTotal + this.devicePageSize - 1) /
this.devicePageSize
);
if (this.devicePageTotal == 0) {
// console.log("沒(méi)有數(shù)據(jù)");
//沒(méi)有數(shù)據(jù)
this.deviceListnodata = true;
this.deviceListIsLoad = false;
this.deviceListIsFinish = true;
this.devicePageNum = 1;
this.deviceTip = "暫無(wú)數(shù)據(jù)";
return false;
}
this.deviceList = this.deviceList.concat(res.body.datas);
// console.log(this.devicePageNum, this.devicePageTotalPages);
if (this.devicePageNum == this.devicePageTotalPages) {
//沒(méi)有更多
this.deviceListIsLoad = false;
this.deviceListIsFinish = true;
this.devicePageNum = 1;
this.deviceTip = "沒(méi)有更多了~";
// console.log("沒(méi)有更多了");
} else {
// console.log("下一頁(yè)");
//下一頁(yè)
this.deviceListIsLoad = true;
this.deviceListIsFinish = false;
this.devicePageNum++;
this.deviceTip = "正在加載中~";
}
// console.log("deviceList", this.deviceList);
} else {
// this.deviceList = [];
this.deviceListIsLoad = false;
this.deviceListIsFinish = true;
this.devicePageNum = 1;
this.deviceTip = "數(shù)據(jù)加載失敗~";
}
});
},
return中的定義
devicePageSize: 10, //每頁(yè)顯示 devicePageNum: 1, //當(dāng)前頁(yè) devicePageTotal: 0, //總條數(shù) devicePageTotalPages: 0, //總頁(yè)數(shù) deviceListIsFinish: false, //是否加載完成 deviceListIsLoad: false, //是否加載更多 deviceListnodata: false, //是否有數(shù)據(jù) deviceTip: "",
總結(jié)
以上所述是小編給大家介紹的vue 實(shí)現(xiàn)滾動(dòng)到底部翻頁(yè)效果(pc端),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- vue+animation實(shí)現(xiàn)翻頁(yè)動(dòng)畫(huà)
- vue 翻頁(yè)組件vue-flip-page效果
- vue-awesome-swiper 基于vue實(shí)現(xiàn)h5滑動(dòng)翻頁(yè)效果【推薦】
- Vue實(shí)現(xiàn)簡(jiǎn)易翻頁(yè)效果源碼分享
- Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁(yè)的實(shí)例
- 基于Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁(yè)功能
- vue router自動(dòng)判斷左右翻頁(yè)轉(zhuǎn)場(chǎng)動(dòng)畫(huà)效果
- 基于vue實(shí)現(xiàn)分頁(yè)/翻頁(yè)組件paginator示例
- 基于Vuejs框架實(shí)現(xiàn)翻頁(yè)組件
- vue實(shí)現(xiàn)數(shù)字翻頁(yè)動(dòng)畫(huà)
相關(guān)文章
vue實(shí)現(xiàn)旋轉(zhuǎn)木馬動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)旋轉(zhuǎn)木馬動(dòng)畫(huà),圖片數(shù)量無(wú)限制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-07-07
vue中實(shí)現(xiàn)一個(gè)項(xiàng)目里兼容移動(dòng)端和pc端
這篇文章主要介紹了vue中實(shí)現(xiàn)一個(gè)項(xiàng)目里兼容移動(dòng)端和pc端問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
vue2.x中keep-alive源碼解析(實(shí)例代碼)
Keep-Alive模式避免頻繁創(chuàng)建、銷毀鏈接,允許多個(gè)請(qǐng)求和響應(yīng)使用同一個(gè)HTTP鏈接,這篇文章主要介紹了vue2.x中keep-alive源碼解析,需要的朋友可以參考下2023-02-02
Electron-vue腳手架改造vue項(xiàng)目的方法
這篇文章主要介紹了Electron-vue腳手架改造vue項(xiàng)目的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10
vue中el-table兩個(gè)表尾合計(jì)行聯(lián)動(dòng)同步滾動(dòng)條實(shí)例代碼
項(xiàng)目開(kāi)發(fā)中遇到一個(gè)比較兩個(gè)form差異的需求,但當(dāng)item過(guò)多就需要滾動(dòng)條,下面這篇文章主要給大家介紹了關(guān)于vue中el-table兩個(gè)表尾合計(jì)行聯(lián)動(dòng)同步滾動(dòng)條的相關(guān)資料,需要的朋友可以參考下2022-05-05
Vue-router中hash模式與history模式的區(qū)別詳解
這篇文章主要給大家介紹了關(guān)于Vue-router中hash模式與history模式區(qū)別的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
vue?同局域網(wǎng)訪問(wèn)不到的問(wèn)題及解決
這篇文章主要介紹了vue?同局域網(wǎng)訪問(wèn)不到的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10

