//index.js //获取应用实例 var app = getApp() Page({ data: { imgUrls: [{ uri:'http://cdn-s3.si.com/s3fs-public/2017/02/27/james-harden-dwight-howard.jpg', txt:'詹姆斯破茧重生', url:'http://bbs.hupu.com/18657042.html', },{ uri:'https://c2.hoopchina.com.cn/uploads/star/event/images/170307/38d602e779e53d8b8bd05f88d76b8563316d6267.jpg', txt:'库班谈塞思-库里:我们希望他永远留在球队', url:'http://bbs.hupu.com/18658465-2.html', },{ uri:'http://cdn.fansided.com/wp-content/uploads/usat-images/2016/04/9874357-nba-san-antonio-spurs-at-new-york-knicks-850x560.jpeg', txt:'卡梅罗-安东尼想赢下总冠军', url:'http://bbs.hupu.com/18626439.html', }], indicatorDots: true, autoplay: true, interval: 5000, duration: 1000, circular: true, zixunList: [], hasRefesh:false, hasMore:true }, swipeTo: function(res){ wx.navigateTo({ url: './details/details?id='+res.currentTarget.id, }) }, listTo:function(res){ wx.navigateTo({ url: './lists/lists?id='+res.currentTarget.id, }) }, //事件处理函数 bindViewTap: function() { wx.navigateTo({ url: '../logs/logs' }) }, onLoad: function () { var that = this; wx.request({ url: "https://www.v2ex.com/api/topics/latest.json", method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // 设置请求的 header success: function(res){ if(res.statusCode == 200){ for(var i in res.data){ res.data[i].chuo = app.getDateDiff(res.data[i].last_touched*1000); } that.setData({ zixunList:res.data }) }else{ wx.showModal({ title: '提示', content: '数据加载失败,请稍后重试', }) } } }); //调用应用实例的方法获取全局数据 app.getUserInfo(function(userInfo){ //更新数据 that.setData({ userInfo:userInfo }) }) }, onPullDownRefresh:function(){ var qita = this; qita.setData({ hasRefesh:true }); wx.showNavigationBarLoading(); wx.request({ url: "https://www.v2ex.com/api/topics/hot.json", method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // 设置请求的 header success: function(res){ if(res.statusCode == 200){ for(var i in res.data){ res.data[i].chuo = app.getDateDiff(res.data[i].last_touched*1000); } qita.setData({ zixunList:res.data }) }else{ wx.showModal({ title: '提示', content: '数据加载失败,请稍后重试', }) } }, complete:function(){ wx.hideNavigationBarLoading() //完成停止加载 wx.stopPullDownRefresh() //停止下拉刷新 qita.setData({ hasRefesh:false }); } }) }, lower:function(e){ console.log(e); } })
|