zoukankan      html  css  js  c++  java
  • 小程序上拉加载的坑 尼古拉斯

    小程序上拉加载的时候,数据请求下来之后会发现数据不会自动叠加,而是一个页面只展示你所请求的数据,所以你要在此把每次请求的数据用concat连接起来,千万不能用push添加,直接上代码

    
    
       data: { //全局变量
          list:'',
          title:'',
          id:'',
          currentPage:'1',
          hasmore:false
         }
     
    onReachBottom() {  //上拉触底函数
       let that = this   //注意that
        console.log(that.data.id)
        console.log(that.data.currentPage++)
        console.log(that.data.list)
        wx.request({
          url: 'http://www.zhm365.com/zhm/api/loadNewByTitle',
          data: {
            title:that.data.id,
            pageSize: '10',
            currentPage:that.data.currentPage++  // 请求页面不能定死,每次请求页面自增,如果页面固定死的话,每次请求的数据相同
          },
          method: 'POST',
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            console.log(res.data.info)
              if(res.data.info!==null){
                //每次刷新的数据叠加,注意是用concat进行连接,而不是用push添加
                that.setData({
                  list: that.data.list.concat(res.data.info),
                  hasmore: true
                })
              }else{
                that.setData({
                  hasmore: true
                })
              }
            }
        })
      },
      
  • 相关阅读:
    HDU6301 SET集合的应用 贪心
    线段树与树状数组的对比应用
    树状数组
    JDBC链接MySQL数据库
    HDU4686Arc of Dream 矩阵快速幂
    HDU1757矩阵快速幂
    B1013. 数素数 (20)
    B1023. 组个最小数 (20)
    [教材]B1020. 月饼 (25)
    [教材]A1025. PAT Ranking (25)
  • 原文地址:https://www.cnblogs.com/xxflz/p/9309681.html
Copyright © 2011-2022 走看看