美文网首页
小程序端加载列表

小程序端加载列表

作者: IT阿泽 | 来源:发表于2020-07-29 15:55 被阅读0次
    //index.js
    //获取应用实例
    const app = getApp()
    var config = require('../../utils/config.js')
    Page({
      data: {
        list: [],
        page: 0,
        size: 10,
      },
      //事件处理函数
      bindViewTap: function () {
      },
      onLoad: function () {
        this.getList(); 
      },
     
      onReady:function(){
       
      },
      onReady:function(){
        console.log('页面打开了')
       },
      onHide:function(){
       console.log('页面隐藏了')
      },
      //点击处理
      goDetail: function (e) {
        console.log('form发生了submit事件,携带数据为:', e)
        wx.navigateTo({
          url: e.currentTarget.dataset.url
        })
      },
      /**
     * 页面上拉触底事件的处理函数
     */ 
      onReachBottom: function () {
        this.getList();
      }, 
      getList: function () {
        var that = this;
        this.setData({ 
          loading: true,
          page: that.data.page + 1
        })
        app._get('wxnew/list', {
          page: that.data.page,
          size: that.data.size 
        }, function(res) {
              if (that.data.page > 1) {
                //下一页的数据拼接在原有数据后面
                that.setData({
                  list: that.data.list.concat(res.data)
                }) 
              } else { 
                //第一页数据直接赋值
                that.setData({
                  list: res.data
                })
              }
              //如果返回的数据为空,那么就没有下一页了
              if (res.data.length == 0) {
                that.setData({
                  noMore: true
                })
              }
            console.log(res.data)
        });
      },
      /**
     * 用户点击右上角分享
     */
      onShareAppMessage: function (res) {
    
      },
      /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
      onPullDownRefresh: function () {
        var that = this;
        that.getBanner();
        wx.showNavigationBarLoading() //在标题栏中显示加载
        //模拟加载
        setTimeout(function () {
          // complete
          wx.hideNavigationBarLoading() //完成停止加载
          that.setData({
            page: 0
          }, function () {
            this.getList();
          })
          wx.stopPullDownRefresh() //停止下拉刷新
        }, 1500);
      }
    })
    
    

    相关文章

      网友评论

          本文标题:小程序端加载列表

          本文链接:https://www.haomeiwen.com/subject/oqzhrktx.html