vue.js加載新的內(nèi)容(實(shí)例代碼)
vue是一種輕巧便捷的框架,那么如何進(jìn)行對(duì)于數(shù)據(jù)加載的刷新呢?以下就是我對(duì)于vue.js數(shù)據(jù)加載的一點(diǎn)想法
源碼:
<div @scroll="onScroll($event)" style="height: 100%;overflow: auto;"> <ul class="shop-brand-index" v-show="sitems.length > 0" > <li v-for="item in sitems"> <div @click="linkUrl(item.code)"><img v-bind:src="item.publicImg"></div> </li> </ul> <div class="loading_wrap myload disn"> <p>加載中...</p> <i class="loading"></i> </div> </div>
解析:
$(function() { var pageNum = 1; var pageSize = 6; vue = new Vue({ el: '#app', data: { items: [], pageNum: pageNum, pageSize: pageSize, rawItems: [], sitems:[] }, methods: { getList: function() { $.showLoading(); this.$http.get(store.list, { pageNum: pageNum, pageSize: pageSize }).then(function(result) { $.removeLoading(); this.sitems = result.data.data.items; }, function() { $.removeLoading(); $.showAlert({ 'title': '提示', 'content': "頁(yè)面偷懶了~~", 'sure': this.close }); }) }, close: function() { history.go(-1); }, onScroll: function(event) { var offsetHeight = event.currentTarget.offsetHeight, scrollHeight = event.target.scrollHeight, scrollTop = event.target.scrollTop, scrollBottom = offsetHeight + scrollTop; if(scrollBottom == scrollHeight+10 ||scrollBottom == scrollHeight) { if(this.pageNum == Math.ceil(this.rawItems.length / this.pageSize)) { return } this.pageNum++; pageNum++; $(".myload").removeClass("disn"); vue.$http.get(store.list, { pageNum: pageNum, pageSize: pageSize }).then(function(result) { setTimeout(function() { $(".myload").addClass("disn"); vue.sitems = vue.sitems.concat(result.data.data.items); }, 2000) }, function() { $(".myload").addClass("disn"); }) } }, }, ready: function() { this.getList(); for(var i = 0; i <= 1000; i++) { this.rawItems.push(i) } } }) })
以上所述是小編給大家介紹的vue.js加載新的內(nèi)容(實(shí)例代碼),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
解決el-date-picker日期選擇控件少一天的問(wèn)題
這篇文章主要介紹了解決el-date-picker日期選擇控件少一天的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10vue實(shí)現(xiàn)websocket客服聊天功能
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)websocket客服聊天功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10Vue中設(shè)置背景圖片和透明度的簡(jiǎn)單方法
在做項(xiàng)目的時(shí)候常需要設(shè)置背景圖片和透明度,下面這篇文章主要給大家介紹了關(guān)于Vue中設(shè)置背景圖片和透明度的簡(jiǎn)單方法,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-01-01詳解Vue開發(fā)微信H5微信分享簽名失敗問(wèn)題解決方案
這篇文章主要介紹了詳解Vue開發(fā)微信H5微信分享簽名失敗問(wèn)題解決方案,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08vue-cropper組件實(shí)現(xiàn)圖片切割上傳
這篇文章主要為大家詳細(xì)介紹了vue-cropper組件實(shí)現(xiàn)圖片切割上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05vue中的input框點(diǎn)擊后不聚焦問(wèn)題
這篇文章主要介紹了vue中的input框點(diǎn)擊后不聚焦問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04vue中動(dòng)態(tài)渲染數(shù)據(jù)時(shí)使用$refs無(wú)效的解決
這篇文章主要介紹了vue中動(dòng)態(tài)渲染數(shù)據(jù)時(shí)使用$refs無(wú)效的解決方案,具有很好的參考價(jià)值。希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01