Heim > Web-Frontend > Uni-App > Hauptteil

uniapp如何实现懒加载

coldplay.xixi
Freigeben: 2023-01-13 00:44:15
Original
9833 人浏览过

uniapp实现懒加载的方法:可以使用【onReachBottom()】这个生命周期函数,让页面滚到到最底部时,进行加载操作,代码为【onReachBottom: function()】。

uniapp如何实现懒加载

本教程操作环境:windows7系统、uni-app2.5.1版本、thinkpad t480电脑。

推荐(免费):uni-app开发教程

uniapp实现懒加载的方法:

在uni-app中,当我们需要让请求的数据进行懒加载时,可以使用onReachBottom()这个生命周期函数,让页面滚到到最底部时,进行加载操作。

这里的p是页码参数,每加载一次,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;
}
})
}
}
Nach dem Login kopieren

相关免费学习推荐:编程视频

以上是uniapp如何实现懒加载的详细内容。更多信息请关注PHP中文网其他相关文章!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Neueste Artikel des Autors
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!