微信小程序> 小程序实现上拉加载更多

小程序实现上拉加载更多

浏览量:488 时间: 来源:荔枝吖

思路:上拉加载更多(页面上拉触底事件),就是将新获取的数据追加到data的原始数据中

const app = getApp();Page({    data: {        movieList: [],        page: 1//分页标识,第几次下拉    },    onLoad() {        var that = this;        this.getMore(that.data.page);    },    onReachBottom: function() {        console.log(1);        swan.showLoading({            title: '加载更多',            make: true        })        var that = this;        this. getMore(that.data.page);        },    getMore: function (page) {        var that = this;        if (page == 1) {            swan.showLoading({                title: ' 加载中',                make: true            })        }        swan.request({            url: 'https://mip.yesky.com/fishVideo/video/movieList.json',            method: 'GET',            data: {                pageNo: page            },            header: {                'content-type': 'application/json'            },            success: function (res) {                var res = res.data.movieList;                if (that.data.page  1) {                    var movieLists = that.data.movieList;                    console.log(movieLists);                    that.setData({                        movieList: movieLists.concat(res),                        page: page + 1                    })                } else {                    that.setData({                        movieList: res,                        page: page + 1                    })                }            }, fail: function () {                swan.showToast({                    title: '服务器异常',                    duration: 1500                })            },            complete: function () {                if (page = 1) {                    swan.hideLoading()                }            }        })    }})

 

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎