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


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

      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,倍感凄凉。
  • 相关阅读:
    2018爆零记第二弹之day0
    2018NOIP爆0记第一弹
    图论中偶然发现的一个问题
    [SCOI2010]序列操作
    CF 675E Trains and Statistic
    CF100015C
    Python 使用 NLTK 实现简单情感分析--Twitter(推特)分析
    pipenv -- python 搭建虚拟环境
    Python
    ElasticSearch 入门教程
  • 原文地址:https://www.cnblogs.com/chengmingxiaowu/p/9847994.html
Copyright © 2020-2023  润新知