Home > WeChat Applet > Mini Program Development > WeChat applet implements rolling data loading

WeChat applet implements rolling data loading

angryTom
Release: 2020-03-09 10:02:28
forward
3427 people have browsed it

This article introduces the method of rolling data loading in WeChat applet. It has certain reference value. I hope it will be helpful to friends who are learning the development of WeChat applet!

WeChat applet implements rolling data loading

Required components and api

##scroll-view (scrollable view area)

wx.showToast(OBJECT) displays the message prompt window----displays the properties used by loading chrysanthemum


Recommended learning:《

小program development

WeChat applet implements rolling data loading##scrol-view needs to specify a height. This height can be calculated according to your own needs. I use the available height of the screen and the default One page displays 6


WeChat applet implements rolling data loadingScroll to the bottom to bind the events that need to be triggered

The operation event function is mainly to use the requested data The concat method is used to merge and then assign values. I use a for loop to pretend to add data. In the actual project, I can replace it with my own ajax. In order to simulate loading, I added a 1.5 second timer. After calling the prompt box api successfully, Close

lower() {
var result = this.data.res;
var resArr = [];
  //这里可以使用自己的ajax
for (let i = 0; i < 10; i++) {
resArr.push(i);
};
var cont = result.concat(resArr);//合并请求的数据
console.log(resArr.length);
if (cont.length >= 100) {
wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中” 
title: &#39;我也是有底线的&#39;,
icon: &#39;success&#39;,
duration: 300
});
return false;
} else {
wx.showLoading({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中” 
title: &#39;加载中&#39;,
icon: &#39;loading&#39;,
});
setTimeout(() => {
this.setData({
res: cont
});
wx.hideLoading();
}, 1500)
}
}
Copy after login

successfully, you can directly copy and run the complete code

js code

Page({
  /**
   * 页面的初始数据
   */
  data: {
    height: &#39;&#39;,
    res: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  },
  lower() {
    var result = this.data.res;
    var resArr = [];
    for (let i = 0; i < 10; i++) {
      resArr.push(i);
    };
    var cont = result.concat(resArr);
    console.log(resArr.length);
    if (cont.length >= 100) {
      wx.showToast({ //如果全部加载完成了也弹一个框
        title: &#39;我也是有底线的&#39;,
        icon: &#39;success&#39;,
        duration: 300
      });
      return false;
    } else {
      wx.showLoading({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”  
        title: &#39;加载中&#39;,
        icon: &#39;loading&#39;,
      });
      setTimeout(() => {
        this.setData({
          res: cont
        });
        wx.hideLoading();
      }, 1500)
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })
      }
    })
  }
})
Copy after login

For more related tutorials, please pay attention to

PHP Chinese website

!

The above is the detailed content of WeChat applet implements rolling data loading. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zixun.jisuapp.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template