微信小程序——上拉、下拉实现

下拉

1. json配置 下拉操作

{
    "enablePullDownRefresh": true
}

2. 下拉代码 onPullDownRefresh

  async onPullDownRefresh() {
        //在当前页面显示导航条加载动画
        wx.showNavigationBarLoading();
        //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
        wx.showLoading({
            title: '刷新中...',
        })
        await this.onLoad()
        //隐藏loading 提示框
        wx.hideLoading();
        //隐藏导航条加载动画
        wx.hideNavigationBarLoading();
        //停止下拉刷新
        wx.stopPullDownRefresh();
    },

上拉 

主要是分页操作

    data: {
        filesArr: [],
        pageSize: 10,
        currentPage: 1,
        total_count: 0,
    },

 

//底部加载
    async onReachBottom() {
        //console.log("触底上滑")
        if (this.data.currentPage * this.data.pageSize >= this.data.total_count) {
            asyncWx.showToast({
                title: "已经到底了!!!"
            })
        } else {
            this.setData({
                currentPage: this.data.currentPage + 1
            })
            await this.getFilesHis()
        }
    },



    async getFilesHis() {
        if (!userInfo.uNo || this.data.total_count <= 0) {
            return
        }
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        res = await asyncWx.request({
            url: appInstance.globalData.host + "/loadFilesRecord",
            header: {
                'content-type': 'application/json' // 默认值
            },
            method: 'POST',
            data: {
                uNo: userInfo.uNo,
                sPage: this.data.currentPage,
                pageCount: this.data.pageSize
            },
        })
        console.log("历史文件记录", res)
        res = res.data.recordset

        this.setData({
            filesArr: this.data.filesArr.concat(res)
        })

        wx.hideLoading({
            success: (res) => {},
        })
        return
    },

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值