微信小程序 scroll-view實(shí)現(xiàn)上拉加載與下拉刷新的實(shí)例
微信小程序 scroll-view實(shí)現(xiàn)上拉加載與下拉刷新的實(shí)例
實(shí)現(xiàn)效果圖:
如圖,使用小程序的scroll-view實(shí)現(xiàn)的上拉加載數(shù)據(jù),下拉刷新數(shù)據(jù),試下代碼如下:
js文件代碼:
var url = "http://192.168.30.4:8080/gtxcx/carrier/getCarrier.action"; var page = 1; var GetList = function (that) { that.setData({ hidden: false }); wx.request({ url: url, data: { pageSize: 10, pageNo: page }, success: function (res) { var l = that.data.list for (var i = 0; i < res.data.length; i++) { l.push(res.data[i]) } that.setData({ list: l }); page++; that.setData({ hidden: true }); } }); } Page({ data: { hidden: true, list: [], scrollTop: 0, scrollHeight: 0 }, onLoad: function () { var that = this; wx.getSystemInfo({ success: function (res) { console.info(res.windowHeight); that.setData({ scrollHeight: res.windowHeight }); } }); }, onShow: function () { var that = this; GetList(that); }, bindDownLoad: function () { var that = this; GetList(that); }, scroll: function (event) { this.setData({ scrollTop: event.detail.scrollTop }); }, refresh: function (event) { page = 1; this.setData({ list: [], scrollTop: 0 }); GetList(this) }, onPullDownRefresh: function () { console.log("下拉") }, onReachBottom: function () { console.log("上拉"); } })
json文件代碼
{ "navigationBarTitleText": "下拉刷新", "enablePullDownRefresh": true, "backgroundTextStyle": "dark" }
wxml文件代碼:
<view class="container"> <scroll-view scroll-top="{{scrollTop}}" scroll-y="true" style="height:{{scrollHeight}}px;" class="list" bindscrolltolower="bindDownLoad" bindscroll="scroll" bindscrolltoupper="refresh"> <view class="item" wx:for="{{list}}"> <image class="img" src="https://cdn.kuaidi100.com/images/all/56/zhongtong.png"></image> <view class="text"> <text class="title">{{item.carrierName}}</text> <text class="description">{{item.carrierTelphone}}</text> <text class="description">{{item.carrierId}}</text> </view> </view> </scroll-view> <view class="body-view"> <loading hidden="{{hidden}}" bindchange="loadingChange"> 加載中... </loading> </view> </view>
wxss文件代碼
.container{ height: 100%; padding: 20rpx; } .item{ display: flex; margin-bottom: 50rpx; width:100%; background:#f0f0f0; overflow:hidden; } .img{ height: 100rpx; width: 100rpx; border-radius: 50%; } .text{ display: flex; flex-shrink:1; flex-grow:1; padding: 10rpx; flex-wrap: wrap; font-size: 50rpx; } .title{ font-size: 50rpx; margin:10rpx 100rpx 10rpx 100rpx; } .description{ font-size: 50rpx; align-self:flex-end; }
注意,
http://192.168.30.4:8080/gtxcx/carrier/getCarrier.action這個(gè)接口就是更具傳入的頁(yè)數(shù),每次返回不同數(shù)據(jù)。
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
用javascript制作qq注冊(cè)動(dòng)態(tài)頁(yè)面
這篇文章主要介紹了用javascript制作qq注冊(cè)動(dòng)態(tài)頁(yè)面,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-04-04TypeScript5.2引入新關(guān)鍵字using介紹
這篇文章主要介紹了TypeScript5.2引入新關(guān)鍵字using使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06threeJs實(shí)現(xiàn)波紋擴(kuò)散及光標(biāo)浮動(dòng)效果詳解
這篇文章主要為大家介紹了threeJs實(shí)現(xiàn)波紋擴(kuò)散及光標(biāo)浮動(dòng)效果詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03微信小程序 require機(jī)制詳解及實(shí)例代碼
這篇文章主要介紹了微信小程序 require機(jī)制詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-12-12JavaScript面試數(shù)組index和對(duì)象key問(wèn)題詳解
這篇文章主要為大家介紹了JavaScript面試數(shù)組index和對(duì)象key問(wèn)題詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12