网站技术分析

一点一滴的积累,一点一滴的沉淀!

微信小程序下拉刷新/上拉加载

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()

},

})

 

打赏 支付宝打赏 微信打赏

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.5.2 Zero

蜀ICP备18016898;版权:2016 @陸仴 

Music