微信小程序 下拉刷新 上拉加载

为了样式好看引入了lin-ui样式

书写wxml前段页面


<scroll-view class="scroll" bindscrolltolower="bottom" scroll-y="{{true}}" bindscrolltoupper="top">
<block wx:for="{{list}}">
  <l-card type="primary" l-img-class="right-card" position="right" image="{{item.pic}}" title="{{item.title}}" bindtap="listInfo" data-id="{{item.id}}">
  <view class="content">
    {{item.desn}}
  </view>
</l-card>
</block>
</scroll-view>


首先在onload中加载出第一页数据

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    list:[]
  },

 /**
   * 生命周期函数--监听页面加载
   * 加载出第一页数据
   */
  onLoad: function (options) {
    wx.request({
      url: 'http://www.exercise.com/word.php/index',
      success:(e)=>{
        let list=e.data.data
        this.setData({list:list})
      }
    })
  },

js中上拉加载事件

bottom(e){
    let that=this
    let page = this.data.page
    page++
    this.setData({page:page})
    wx.request({
      url: 'http://www.exercise.com/word.php/index',
      data:{
        page:page
      },
      success:(res)=>{
        // let list= e.data.data
        // this.setData({list:list})
        console.log(res);
        console.log(that.data.list);
        let list = res.data.data;
        if(list.length > 0){
          wx.showToast({
            title: '加载中....',
            icon:"loading",
            duration:99999
          });
          that.setData({
            list:[...that.data.list,...list]
          });
          wx.showToast({
            icon:"none",
            duration:100
          })
        }else{
          wx.showToast({
            title: '没有更多啦!',
            icon:"none",
            duration:2000
          })
        }
      }
    })
  },

下拉刷新

/**
   * 滑轮触碰顶部事件
   */
  top(e){
    wx.request({
      url: 'http://www.exercise.com/word.php/index',
      data:{
        page:1
      },
      success:(res)=>{
        let list = res.data.data;
        this.setData({list:list})
        wx.showToast({
          title: '刷新成功',
          icon: 'success',
          duration: 1000
        })
      }
    })
  },

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呀哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值