var app = getApp(),api = app.globalData.api;
var page= 1
Page({
data: {
list: []
},
/*自动加载博客列表*/
onLoad: function () {
const token = wx.getStorageSync('token');
var that = this;
wx.showLoading({
title: '玩命加载中',
})
wx.request({
method: 'GET',
url: 'http://sjyme.cn', //接口
data: {
token: token.token,page: page
},
header: {'content-type': 'application/json' // 默认值 get请求},
success: function (res) {
/* 回调函数*/
var dataList = that.data.list;
if (res.data.code==200 && res.data.data!=''){
for (var i = 0; i < res.data.data.length; i++) {
dataList.push(res.data.data[i]);
}
// 设置数据
that.setData({
list: dataList
})
// 隐藏加载框
wx.hideLoading();
page++;
}else{
setTimeout(function () {
wx.showToast({title: '没有数据了'})
}, 1000)
}
},
fail: function () {
console.log(666)
},
complete: function () {
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
}
})
},
/*下拉刷新*/
onPullDownRefresh: function () {
var that = this;
page = 1
that.setData({
list: []
})
// 显示顶部刷新图标
wx.showNavigationBarLoading();
this.onLoad()
},
/** 页面上拉触底事件的处理函数*/
onReachBottom: function () {
this.onLoad()
},
})