小程序学习之旅----上拉刷新实例

xiaoxiao2025-10-10  22

Page({ /** * 页面的初始数据 */ data: { list: [], windowHeight: '400', page: 1, flag: true }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.requestData() //获取屏幕高度 var that = this; wx.getSystemInfo({ success: function (res) { console.log(res.model) console.log(res.pixelRatio) console.log(res.windowWidth) console.log(res.windowHeight) console.log(res.language) console.log(res.version) console.log(res.platform) that.setData({ windowHeight: res.windowHeight }) } }) }, requestData () { this.setData({ flag: false }) var that = this var api = 'http://www.phonegap100.com/appapi.php'; wx.request({ url: api, //仅为示例,并非真实的接口地址 data: { a: 'getPortalList', catid: '20', page: that.data.page }, header: { 'content-type': 'application/json' // 默认值 }, success (res) { if (res.data.result.length < 20) { var f = false; } else { var f = true; } console.log(res.data) var list = that.data.list.concat(res.data.result) var page = ++that.data.page; that.setData({ list: list, page: page, flag: f }) } }) }, loadMore () { if (this.data.flag) { this.requestData(); } } }) <scroll-view scroll-y style="height:\{\{windowHeight\}\}px" bindscrolltolower="loadMore"> <view class="list"> <view class="item" wx:for='{{list}}' wx:key='{{index}}'> {{item.title}} </view> </view> </scroll-view>

 

转载请注明原文地址: https://www.6miu.com/read-5037691.html

最新回复(0)