文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

微信小程序实现本地分页加载

2024-04-02 19:55

关注

本文实例为大家分享了微信小程序实现本地分页加载的具体代码,供大家参考,具体内容如下

先看看效果图:

下面附上代码:(这些图片的地址记得改成自己的)

1、js文件:

// pages/shoplist/shoplist.js
Page({
 
  
  data:{
 
    query:{},
    "list":[
      {
        "id":"1",
        "name":"apple",
        "image":"/shoplist_images/apple.png",
        "address":"砖井村",
        "tel":"18601416781"
      },
      {
        "id":"2",
        "name":"avocado",
        "image":"/shoplist_images/avocado.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"3",
        "name":"avocado_1",
        "image":"/shoplist_images/avocado_1.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"4",
        "name":"banana",
        "image":"/shoplist_images/banana.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"5",
        "name":"barbecue",
        "image":"/shoplist_images/barbecue.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"6",
        "name":"beer",
        "image":"/shoplist_images/beer.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"7",
        "name":"beer_mug",
        "image":"/shoplist_images/beer_mug.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"8",
        "name":"birthday_cake",
        "image":"/shoplist_images/birthday_cake.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"9",
        "name":"bone",
        "image":"/shoplist_images/bone.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"10",
        "name":"bottle",
        "image":"/shoplist_images/bottle.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"11",
        "name":"bowl",
        "image":"/shoplist_images/bowl.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"12",
        "name":"bread",
        "image":"/shoplist_images/bread.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"13",
        "name":"bread_2",
        "image":"/shoplist_images/bread_2.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"14",
        "name":"cake_1",
        "image":"/shoplist_images/cake_1.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"15",
        "name":"cake_2",
        "image":"/shoplist_images/cake_2.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"16",
        "name":"cake_3",
        "image":"/shoplist_images/cake_3.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"17",
        "name":"cake_4",
        "image":"/shoplist_images/cake_4.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"18",
        "name":"cake_5",
        "image":"/shoplist_images/cake_5.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"19",
        "name":"candy",
        "image":"/shoplist_images/candy.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"20",
        "name":"canned_fruit",
        "image":"/shoplist_images/canned_fruit.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"21",
        "name":"carrot",
        "image":"/shoplist_images/carrot.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"22",
        "name":"chafing_dish_2",
        "image":"/shoplist_images/chafing_dish_2.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"23",
        "name":"chafing_dish",
        "image":"/shoplist_images/chafing_dish.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"24",
        "name":"cheese",
        "image":"/shoplist_images/cheese.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"25",
        "name":"chef_hat",
        "image":"/shoplist_images/chef_hat.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"26",
        "name":"cherry",
        "image":"/shoplist_images/cherry.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"27",
        "name":"chicken",
        "image":"/shoplist_images/chicken.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"28",
        "name":"chicken_leg",
        "image":"/shoplist_images/chicken_leg.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"29",
        "name":"crab",
        "image":"/shoplist_images/crab.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"30",
        "name":"fish",
        "image":"/shoplist_images/fish.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"31",
        "name":"hamburger",
        "image":"/shoplist_images/hamburger.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"32",
        "name":"hot_pot",
        "image":"/shoplist_images/hot_pot.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"33",
        "name":"lemon",
        "image":"/shoplist_images/lemon.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"34",
        "name":"popcorn",
        "image":"/shoplist_images/popcorn.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"35",
        "name":"popcorn_2",
        "image":"/shoplist_images/popcorn_2.png",
        "address":"砖井村",
        "tel":"186"
      },
      {
        "id":"36",
        "name":"snacks",
        "image":"/shoplist_images/snacks.png",
        "address":"砖井村",
        "tel":"186"}],   
      i:0,//表示当前item项个数
      shoplist:[],
      result:[],
      isloading:false
    },
  
  onLoad(options) {
    this.setData
    ({
      query:options
    })
    this.getshoplist()
    
  },
  getshoplist()
  {
    //当页面加载完毕时停止继续发出请求
    if(this.data.i>this.data.result.length)
    {
      return wx.showToast({
        title: '数据加载完毕!',
        icon:'none'
      })
    }
    //防止多次下滑触底从而发出多次请求
    this.setData({isloading:true}),
    wx.showLoading({
      title: '数据加载中...',
    })
    this.data.shoplist=this.data.list.slice(this.data.i,this.data.i+10)
      this.setData({
        i:this.data.i + 10
        })
        this.data.result=this.data.result.concat(this.data.shoplist)
        this.setData({
          result:this.data.result
        })
        wx.hideLoading()
        this.setData({isloading:false})
  },
 
  
  onReady() {
    wx.setNavigationBarTitle({
      title: this.data.query.title,
    })
  },
 
  
  onShow() {
 
  },
 
  
  onHide() {
 
  },
 
  
  onUnload() {
 
  },
 
  
  onPullDownRefresh() {
 
  },
 
  
  onReachBottom() {
    if(this.data.isloading) return
    this.getshoplist()
  },
 
  
  onShareAppMessage() {
 
  }
})

2、json文件

{
  "usingComponents": {},
  "onReachBottomDistance": 200
}

3、wxml文件

<!--pages/shoplist/shoplist.wxml-->
<view wx:for="{{result}}" wx:key="id" class="shop-item">
     <image src="{{item.image}}" class="thumb"></image>
  <view class="shop-item-item">
     <view class="shop-title">商品名:{{item.name}}</view>
     <view>店铺地址:{{item.address}}</view>
     <view>联系电话:{{item.tel}}</view>
  </view>
</view>

4、wxss文件


.shop-item{
  display:flex;
  border: 1rpx solid rgb(216, 194, 194);
  border-radius: 50rpx;
  margin: 15rpx;
  box-shadow: 1rpx 1rpx 15rpx rgb(146, 102, 102);
}
.thumb
{
  width: 320rpx;
  height: 320rpx;
  display: block;
  margin-right: 15rpx;
  padding: 15rpx;
}
.shop-item-item
{
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  font-size: 30rpx;
}
.shop-title
{
  font-weight: bold;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-前端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯