Through many crawling pits, I discovered that these methods of listening to scrolling to load more components have something in common. Because these methods of loading more components are bound to elements that need to load more content, they enter the page. Then it is triggered once directly, and after the scroll event is monitored, it continues to load more, so there is no need to write a function for the first load list for infinite scroll loading. This article will share with you an article on the Vue.js mobile component library mint-ui to achieve infinite scrolling and loading more methods. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.
The code is as follows:
html:
//父组件//LifeLists组件:
LifeListItem组件:
{{item.title}}
{{item.monetaryUnit}}{{item.price}}
{{item.title}}
发布于{{formatTime(item.createAt)}} {{item.countryName}} {{item.cityName}}
{{item.detail}}
{{item.like}}
{{item.commentCount}}
vue.js
data:
page:0, size:10, loadingTextBtn:false, loadingText:"努力加载中", loadingComplete:false, refreshComplete:false, city:"", country:""
methods:
loadMore() { this.loading = true; this.loadingTextBtn=true; if(parseInt(this.page)==0){ this.$store.dispatch('loadMoreLifeList',{city:"纽约",country:"美国",category:"",page:this.page,size:this.size}); this.page++; }else if(parseInt(this.page)>0&&parseInt(this.page){ // this.$store.dispatch('loadMoreLifeList',{city:this.city,country:this.country,category:"",page:this.page,size:this.size}) this.$store.dispatch('loadMoreLifeList',{city:"纽约",country:"美国",category:"",page:this.page,size:this.size}); this.page++; }, 1000); }else{ this.loadingText="已全部加载完成"; this.loadingComplete=true; this.loading = false; } },
The important thing here is to judge that when the current page is 0, that is, the first page, there is no need for a setTimeout timer and a direct request to load. When more is loaded, a timer can be added.
I found a lot of mint-ui loadmore components on the Internet to implement pull-up to load more. Since the pull-up triggers the corresponding load more event, the data should not be automatically loaded when entering the page, so here You can add a function to get the first page of data.
Related recommendations:
How to implement it in vue Scroll to load more functions
Detailed explanation of CSS3 to achieve infinite loop seamless scrolling
The above is the detailed content of Detailed explanation of Vue.js's mobile component library mint-ui to achieve infinite scrolling loading more. For more information, please follow other related articles on the PHP Chinese website!