小程序下拉刷新和上拉加载

xiaoxiao2021-02-28  43

 

Page({

data: {

isLoading: false,

page: 1,

isMore: true,

thisPage: '',

videoList: [],

},

// 页面加载事件

onLoad: function (options) {

this.refresh()

},

// 刷新方法

refresh() {

if (this.data.isLoading) {

return

}

this.data.page = 1

this.data.isMore = true

this.data.videoList = []

this.getVideoList()

},

// 加载更多方法

loadMore() {

if (this.data.isLoading) {

return

}

if (this.data.isMore == false) {

return

}

this.data.page += 1

this.getVideoList()

},

// 从服务器获取视频列表数据

getVideoList() {

this.data.isLoading = true

wx.showNavigationBarLoading()

wx.request({

url: yourUrl,

method: 'GET',

data: {

page: this.data.page,

        paras: your.other.paras

},

header: {

},

complete: res => {

this.data.isLoading = false

wx.stopPullDownRefresh() //停止下拉刷新

wx.hideNavigationBarLoading() //完成停止加载

        if(res.statusCode == 200) { 

          if (res.data.meta.pagination.total_pages == res.data.meta.pagination.current_page) {

this.data.isMore = false

  }

          // 这里的pagination参数是该项目接口中的分页数据

this.data.videoList = this.data.videoList.concat(res.data.data)

        }

}

})

},

// 下拉刷新事件

onPullDownRefresh: function () {

this.refresh()

},

// 上拉加载事件

onReachBottom: function () {

this.loadMore()

}

})

 

转载请注明原文地址: https://www.6miu.com/read-2620495.html

最新回复(0)