• 小程序上拉加载,下拉刷新


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

      data: {
        collectinformation: null,
        number: 1,
        size: 10,
        isOpenLoading: true,
        isEmpty: true,
        isLoadingTrue: true,
        mylist: null,
        mylists: null,
      },
    onPullDownRefresh部分代码
      //下拉刷新
      onPullDownRefresh: function(e) {
        this.setData({
          isEmpty: true,
          number: 1,
          mylist: [],
          isLoadingTrue: true
        })
        this.getList();
      },
    onReachBuottom部分
    isOpenLoading就是添加的闸门,目的是防止一个方法还没有结束就发起另外一个请求,造成num的混乱
      onReachBottom: function(e) {
        if (this.data.isOpenLoading) {
          this.getList()
        } else {
          return
        }
      },
    getList()部分
    call.myRequest这边被我封装了,可以直接用自己的
    getList: function() {
        var that = this
        that.setData({
          mylists: [],
          isShowIcon: false,
          isOpenLoading: false
        })
        wx.showNavigationBarLoading()
        var myData = {
          category: 0,
          number: that.data.number,
          size: that.data.size
        }
        call.myRequest("/user/collections/", that.listSuc, "POST", myData)
      },
      listSuc: function(data, res) {
        var that = this
        var totalList = [];
        that.data.mylists = data.value
        if (!that.data.mylists || !that.data.mylists.length) {
          that.setData({
            isLoadingTrue: false,
            isShowIcon: true,
            isOpenLoading: false
          });
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          return
        }
        if (!that.data.isEmpty) {
          totalList = that.data.mylist.concat(that.data.mylists);
        } else {
          totalList = that.data.mylists
          that.data.isEmpty = false
        }
        that.setData({
          mylist: totalList,
          isLoadingTrue: true,
          isShowIcon: true,
          isOpenLoading: true
        })
        wx.hideNavigationBarLoading();
        wx.stopPullDownRefresh();
        that.data.number += 1
      },

    onLoad部分

      onLoad: function(options) {
        this.$wuxRater = app.Wux().$wuxRater
        wx.setNavigationBarTitle({
          title: '我的收藏',
        })
        this.onPullDownRefresh()
      },
    有个不太友好的问题就是在刷新的时候我就清空了mylists中的数据,虽然加了loading,感觉还是不太好。尤其是在突然断网的情况下,页面上就剩下几个loading,倍感凄凉。
  • 相关阅读:
    Jump Game II
    Trapping Rain Water
    First Missing Positive
    Median of Two Sorted Arrays
    noip2012开车旅行 题解
    AC自动机专题总结
    初探数位DP
    斯坦纳树 [bzoj2595][wc2008]游览计划 题解
    [bzoj3244][noi2013]树的计数 题解
    网络流模型小结
  • 原文地址:https://www.cnblogs.com/chengmingxiaowu/p/9847994.html
Copyright © 2020-2023  润新知