//index.js
//获取应用实例
const app = getApp()
var config = require('../../utils/config.js')
Page({
data: {
list: [],
page: 0,
size: 10,
},
//事件处理函数
bindViewTap: function () {
},
onLoad: function () {
this.getList();
},
onReady:function(){
},
onReady:function(){
console.log('页面打开了')
},
onHide:function(){
console.log('页面隐藏了')
},
//点击处理
goDetail: function (e) {
console.log('form发生了submit事件,携带数据为:', e)
wx.navigateTo({
url: e.currentTarget.dataset.url
})
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getList();
},
getList: function () {
var that = this;
this.setData({
loading: true,
page: that.data.page + 1
})
app._get('wxnew/list', {
page: that.data.page,
size: that.data.size
}, function(res) {
if (that.data.page > 1) {
//下一页的数据拼接在原有数据后面
that.setData({
list: that.data.list.concat(res.data)
})
} else {
//第一页数据直接赋值
that.setData({
list: res.data
})
}
//如果返回的数据为空,那么就没有下一页了
if (res.data.length == 0) {
that.setData({
noMore: true
})
}
console.log(res.data)
});
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function (res) {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
var that = this;
that.getBanner();
wx.showNavigationBarLoading() //在标题栏中显示加载
//模拟加载
setTimeout(function () {
// complete
wx.hideNavigationBarLoading() //完成停止加载
that.setData({
page: 0
}, function () {
this.getList();
})
wx.stopPullDownRefresh() //停止下拉刷新
}, 1500);
}
})
网友评论