How to implement lazy loading in uniapp: You can use the life cycle function [onReachBottom()] to perform the loading operation when the page scrolls to the bottom. The code is [onReachBottom: function()].
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, thinkpad t480 computer.
Recommended (free): uni-app development tutorial
Uniapp’s method of implementing lazy loading:
In uni-app, when we need to lazy load the requested data, we can use the onReachBottom()
life cycle function to scroll the page to the bottom. when, perform the loading operation.
The p here is the page number parameter, each time it is loaded, per 1.
onLoad() { // ajax请求 this.ajaxCode(this.per) }, onReachBottom: function() { // 下拉懒加载 ++this.per; uni.request({ url: 'https://www.zrzj.com/api/index/homePage', method: 'get', data: { p: this.per }, success: (res) => { var next_data = res.data.result // 加载新数组 this.products = this.products.concat(next_data) } }) }, methods: { ajaxCode(per) { uni.request({ url: 'https://www.zrzj.com/api/index/homePage', method: 'get', data: { p: per }, success: (res) => { var _data = res.data.result this.products = _data; } }) } }
Related free learning recommendations: Programming video
The above is the detailed content of How to implement lazy loading in uniapp. For more information, please follow other related articles on the PHP Chinese website!