600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 微信小程序 实现列表刷新的实例详解

微信小程序 实现列表刷新的实例详解

时间:2024-03-10 20:38:00

相关推荐

微信小程序 实现列表刷新的实例详解

微信小程序|小程序开发

微信小程序 列表刷新

微信小程序-小程序开发

微信小程序 列表刷新:

easyjforum 源码,vscode 默认模版,ubuntu 显示,tomcat 跟踪调试,c sqlite3查询,discuz 插件链接,做后台前端最好的框架,水斗下的爬虫怎么处理,php 数组 url参数,济宁seo推广推荐,网站本地采集,网页探针是什么,黑色主题html模板lzw

微信小程序,最近自己学习微信小程序的知识,就想实现现在APP 那种列表刷新,下拉刷新,上拉加载等功能。

淘宝客小程序 源码,ubuntu18循环,tomcat服务器下载速度,爬虫买卖app,php网站建设方案书实例,刘鑫seolzw

先开看一下界面

有声小说站源码,联想装了ubuntu,tomcat5.5连接数,小朋友python爬虫,菜刀一句话php,金牌seo 海报lzw

1.wx.request (获取远程服务器的数据,可以理解成$.ajax)

2. scroll-view的两个事件

2.1 bindscrolltolower(滑到页面底部时)

2.2 bindscroll (页面滑动时)

2.3 bindscrolltoupper (滑倒页面顶部时)

然后我们看代码,详细描述。

index.js

var url = "/course/ajaxlist";var page =0;var page_size = 20;var sort = "last";var is_easy = 0;var lange_id = 0;var pos_id = 0;var unlearn = 0; // 获取数据的方法,具体怎么获取列表数据大家自行发挥var GetList = function(that){ that.setData({ hidden:false }); wx.request({ url:url, data:{page : page,page_size : page_size,sort : sort,is_easy : is_easy,lange_id : lange_id,pos_id : pos_id,unlearn : unlearn }, success:function(res){//console.info(that.data.list);var list = that.data.list;for(var i = 0; i < res.data.list.length; i++){ list.push(res.data.list[i]);}that.setData({ list : list});page ++;that.setData({ hidden:true}); } });}Page({ data:{ hidden:true, list:[], scrollTop : 0, scrollHeight:0 }, onLoad:function(){ // 这里要非常注意,微信的scroll-view必须要设置高度才能监听滚动事件,所以,需要在页面的onLoad事件中给scroll-view的高度赋值 var that = this; wx.getSystemInfo({success:function(res){ console.info(res.windowHeight); that.setData({ scrollHeight:res.windowHeight });} }); }, onShow:function(){ // 在页面展示之后先获取一次数据 var that = this; GetList(that); }, bindDownLoad:function(){ // 该方法绑定了页面滑动到底部的事件 var that = this; GetList(that); }, scroll:function(event){ // 该方法绑定了页面滚动时的事件,我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。 this.setData({scrollTop : event.detail.scrollTop }); }, refresh:function(event){ // 该方法绑定了页面滑动到顶部的事件,然后做上拉刷新 page = 0; this.setData({list : [],scrollTop : 0 }); GetList(this) }})

index.wxml

{{item.name}} {{item.short_description}} 加载中...

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多微信小程序 实现列表刷新的实例详解相关文章请关注PHP中文网!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。