微信小程序各种下拉刷新、下拉加载、页面后退刷新

https://m.jb51.net/article/124822.htm 

https://www.jianshu.com/p/4be8d10d2724

假设从页面A后退到页面B时B需要刷新,那么可以在B里面写:

onshow:function(){
    this.onLoad();
},

一、在app.json中,将window选项中的enablePullDownRefresh设为true (单页面不需要window)

"window":{ 
   "enablePullDownRefresh":true,
  "backgroundTextStyle": "dark"
} 

      或者在要刷新的界面的XXX.json中设置enablePullDownRefresh设为true   

  "enablePullDownRefresh":true,
  "backgroundTextStyle": "dark",


// 下拉刷新
  onPullDownRefresh: function () {
    wx.setNavigationBarTitle({
      title: '拼命加载中...'
    }); 
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.onLoad() // 页面重新加载
    this.mydatas();// 或者请求数据
    setTimeout(function () {
      wx.setNavigationBarTitle({
        title: '我的'
      }); 
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, 1000);
  },


//请求函数
mydatas(){
    let token = wx.getStorageSync('token')
    BaseApi.fenxiao({ //分销和my接口一起
      token: token
    }).then((res) => {
      console.log(res);
      if (res.data.code == 200) {
        let datas = res.data.data;
        this.setData({
          vip_name: datas.vip_name,
        })
      }
    }, (err) => {

    });
  },

上拉刷新:

data() {
			return {
				pindex: 1,
				psize: 15,
				newsList: [],
				totlePage: 0,
				onoff:false,
				newsLength: -1
			}
		},

上拉:
onPullDownRefresh: function() {
			this.pindex = 1
			this.newsList = []
			this.newsLength = -1
			this.getNews() //重新赋值,重新请求数据
		},

下拉加载:
onReachBottom: function() {
			if(this.pindex > this.totalPage){
				this.onoff = true //到底
			}else{
				self.getNews()
			}
		},

getNews: function() {
				uni.showLoading({
					title:'加载中...'
				}),
				n.post("gls/getArticleList", {
					pindex: this.pindex,
					psize: this.psize,
				}, function(res) {
					
					if(res.request.errno == 0){
						if(!res.request.data.length){
							self.newsLength = 0
							uni.hideLoading()
							uni.stopPullDownRefresh()
							return
						}
						var Arr = self.newsList
						var newArr = Arr.concat(res.request.data)
						self.newsList = newArr
						self.totalPage = res.request.total_page
						self.newsLength = self.newsList.length
						self.pindex++
					}else{
						wx.showToast({
							title: res.request.message,
							icon: 'none',
							duration: 2000
						})
					}
					uni.hideLoading()
					uni.stopPullDownRefresh()
				},function(res){
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
			},

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值