婚戀交友原始碼開發,移動端滾動載入更多元件的實現
前言
實現
<template> <div id="loadMore" > <slot></slot> <div id="loadTips" v-if="totalCount > 0 && totalCount >= pageSize" > <i v-show="loadTips=='正在載入中'" ></i> {{loadTips}} </div> </div> </template> <script> let timer = null // 不作為響應式變數,提升效能 export default { props: { pageIndex: { type: Number, default: 1 }, pageSize: { type: Number, default: 10 }, totalCount: { type: Number, default: 0 }, delay: { type: [Number], default: 500 }, // 滾動條到達底部多少就會自動請求資料 bottom: { type: [Number], default: 25 }, // 請求失敗預防針,測試中發現的這個 fail: { type: Boolean, default: false }, failTips: { type: String, default: '請求失敗,稍候重試!' } }, data () { return { loadTips: '正在載入中' }; }, watch: { pageIndex () { this.loadMore() }, totalCount: { handler (val, oldval) { if (val > 0) { this.loadMore() } }, // 首次請求 immediate: true }, fail (value) { if (value) { this.loadTips = this.failTips } } }, methods: { // 上滑動載入更多 loadMore () { this.loadTips = '正在載入中'; const {pageSize, pageIndex, totalCount} = this return new Promise((resolve, reject) => { window.onscroll = () => { timer = setTimeout(() => { if (!document.getElementById('loadTips')) return const clientHeight = document.documentElement.clientHeight || document.body.clientHeight || 0 const rectBottom = document.getElementById('loadTips').getBoundingClientRect().bottom || 0 if (rectBottom < clientHeight + this.bottom) { const size = totalCount - pageIndex * pageSize if (size > 0) { this.$emit('loadmore', pageIndex + 1) resolve(true) } else { this.loadTips = '沒有更多資料了' resolve(false) } clearTimeout(timer) } }, this.delay) } }) } }, beforeDestroy () { clearTimeout(timer) } }; </script> <style scoped> .loadmore-tip { color: #aaa; font-size: 12px; text-align: center; height: 40px; line-height: 40px; } @keyframes rotate-loading { 0% { -webkit-transform: rotate(0); transform: rotate(0); } 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } @-webkit-keyframes rotate-loading { 0% { -webkit-transform: rotate(0); transform: rotate(0); } 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } .loadmore-icon { vertical-align: -2px; width: 12px; height: 12px; display: inline-block; background: url("data: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q9/eKACnO2jJcEaLU8eX12sontiUmu5P7tD0TrJ/OtVUPGLo5YVzPChMaZhPLmqLB7WL3vmGwnizg5vXweab9+iqi9LRe2b2ih0cuMRj9km6d2un7brZCniYqMfrmmXSLBua+lfWbFiY1Nmu2lmRTSZpOM59b+LDTPJmpFaKKQ0ZMhe/anDJID9tqj4+ugLjq3K+9SVfhRkro1XvSieMWgXsVJ0R5nRWuePXB2AsrBWyRbXrMGtAWTHUBiN9QkWkD+a1VdQzfD8kXJaGYGZZhTtgf8zFhANjW7BnSndhM/nSJ0o51T7Y1yX6AvUnF6fscqjHQNE1QK9clMhwgZoV1ueE/Sa++zwhACer90SfF+TigZHPOcJIvisMEv5FCf2RChHEINPfbhCl10gBaog+6qEXthK6m5IU7ixi4hN8JhvcPC4NOH4Y/pKvGfJr5yiJ8Y39dJWs+C2FFn9yvAtKPOC/HHACj9dFVnweD3iOAE14wGukqhV4QCL9djwedYV0OkTghxwwhAj054BBRODTHPASIpBUzWVEoAUbOIK9ZD32Q/Fhlw16YaNvPXRxQJcvdIGlOpFbAPUbu0lBG/XgAf+SRr+FuGYrxqtIZeG48YAKog+qSTwiwgtnmQVCNHEhjkeEl3YbHpA5VqzhEQOSDj7VAo5mdjUa8DUcHp/H0Ihroo+3dVuBiAN4zVAyFsG6FouYNzGMCSzi6D0g+tCqx/RKmBHEHXdfMO6T7R2PIy2fTvnmVt5MC3GZaT8sqe98nvUd1u4L79dO2w9n+8bPX1/5LPv9IWtIbtNVe6GS3mYMyQNeN9LRXGSZLnuXSi3TJe9ywTJNf+SpPSWmrmrK+sx7m755P9hvnSqxtg0Bvk9b5+RjOwd1AgpohtsYnxHaC3Gte+gMnjN75Z8L9jOPFB3WnJK/P7I/VuUfs0V7TrncmP8jtvO4FdRBjgAAAABJRU5ErkJggg==") no-repeat; background-size: 12px 12px; -webkit-animation: rotate-loading 0.5s linear forwards infinite; animation: rotate-loading 0.5s linear forwards infinite; } </style>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69996194/viewspace-2844665/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何實現婚戀app原始碼移動端網頁特效?APP原始碼網頁特效
- 在婚戀app原始碼開發中,如何實現滑動驗證碼元件?APP原始碼元件
- 婚戀交友原始碼開發,採用連線複用實現效能優化原始碼優化
- 移動端無限滾動載入 js實現原理JS
- 婚戀交友原始碼是如何與MySQL打交道的?原始碼MySql
- 婚戀app原始碼開發,如何實現介面效能優化?APP原始碼優化
- 如何實現婚戀app原始碼中直播首屏載入優化?APP原始碼優化
- 婚戀交友原始碼開發,關於API介面安全性問題的思考原始碼API
- js實現 web頁面的滾動條下拉時載入更多JSWeb
- 相親交友原始碼實現相親直播間,移動終端的優化方案原始碼優化
- 影片相親交友系統開發,引領婚戀交友新玩法
- 夢幻婚戀交友app系統原始碼影片聊天直播過程加密原生開發APP原始碼加密
- 線上直播系統原始碼,實現翻頁載入、下拉滾動載入原始碼
- 開發婚戀交友原始碼可以使用的四種架構,各有什麼優缺點原始碼架構
- iSlider移動端原生滑動元件原始碼解讀IDE元件原始碼
- 讓人頭疼的婚戀交友原始碼效能優化,該如何解決?原始碼優化
- 滾動載入圖片(懶載入)實現原理
- 如何實現婚戀app原始碼中元素水平垂直居中?APP原始碼
- angular 監聽 Windows 滾動事件 實現頁面滾動載入AngularWindows事件
- 直播帶貨app原始碼,實現移動端的按鈕拖動APP原始碼
- 移動端模擬滾動
- H5移動端獲獎無縫滾動動畫實現H5動畫
- 實現基於React的移動端Swiper元件React元件
- 移動端Modal元件開發雜談元件
- 移動端div跟隨滾動條滾動(自制
- 短影片app原始碼,Vue3滾動載入APP原始碼Vue
- 解決移動端滾動穿透穿透
- 影片直播app原始碼,vue實現列表自動滾動的方式APP原始碼Vue
- 相親婚戀交友系統前景如何?開發要注意哪些問題?
- 婚戀app原始碼開發,值得一看的前端加密方法APP原始碼前端加密
- 直播原始碼開發,實現 scroll-view 自動滾動到底部,並控制觸發頻率原始碼View
- 移動端開發——關於區域性區域滾動總結 | 實戰系列
- 移動端日曆元件設計與實現元件
- element ScrollBar滾動元件原始碼深入分析元件原始碼
- 【移動端開發】移動端開發基礎問題
- 直播平臺原始碼,迴圈滾動RecyclerView的實現原始碼View
- 移動端滾動穿透解決方案穿透
- 移動端用下拉重新整理的方式實現上拉載入