💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 将请求函数封装实现瀑布流 ~~~ //index.js //获取应用实例 const app = getApp() Page({ data: { list: [], count: 0, show:false }, onLoad() { this.http() }, onReachBottom: function () { // 到底部下拉加载时最上方显示加载图标 wx.showNavigationBarLoading(); var self = this; self.setData({ count: self.data.count + 20, }); this.http() }, http() { var self = this; wx.request({ // url: 'https://www.easy-mock.com/mock/5bac6e450132334db716717d/test/test', url: `https://douban.uieee.com/v2/movie/top250?start${self.data.count}&count=${self.data.count + 20}`, header: { 'Content-Type': 'json' }, success: function (res) { // var dat=res.data; var data = res.data.subjects; var list = []; for (let key in data) { var temp = {}; // console.log(data[key]); temp.title = data[key].title; temp.images = data[key].images.small; temp.average = data[key].rating.average; list.push(temp); } // console.log(list) self.setData({ list, /页面加载时取消加载图标 show:true }); // 当加载完毕时取消顶部加载图标 wx.hideNavigationBarLoading() } }); } }) ~~~ ### index.js(未封装) ~~~ //index.js //获取应用实例 const app = getApp() Page({ data:{ list:[], count:0, show:false }, onLoad(){ var self=this; wx.request({ // url: 'https://www.easy-mock.com/mock/5bac6e450132334db716717d/test/test', url: `https://douban.uieee.com/v2/movie/top250?start${self.data.count}&count=${self.data.count+20}`, header: { 'Content-Type': 'json' }, success: function(res) { // var dat=res.data; var data=res.data.subjects; // var data=res.data.data; // self.setData({ // data, // }); // console.log(res) // console.log(data); // temp.title=; var list=[]; for(let key in data){ var temp={}; // console.log(data[key]); temp.title=data[key].title; temp.images=data[key].images.small; temp.average=data[key].rating.average; list.push(temp); } //console.log(list) self.setData({ list, /页面加载时取消加载图标 show:true }); } }); }, //当页面滑到最底部时触发的事件(请求数据部分和上面的onload里面的求一样) onReachBottom: function () { // 到底部下拉加载时最上方显示加载图标 wx.showNavigationBarLoading(); var self=this; // console.log(this.data.count) self.setData({ count:self.data.count+20, }); // console.log(this.data.count) // console.log(this.data.list); // var count =20; wx.request({ url: `https://douban.uieee.com/v2/movie/top250?start${self.data.count}&count=${self.data.count+20}`, header: { 'Content-Type': 'json' }, success: function(res){ // console.log(res); var data=res.data.subjects; var list=[]; for(let key in data){ var temp={}; // console.log(data[key]); temp.title=data[key].title; temp.images=data[key].images.small; temp.average=data[key].rating.average; list.push(temp); } self.setData({ list, /页面加载时取消加载图标 show:true }); // 当加载完毕时取消顶部加载图标 wx.hideNavigationBarLoading() } }) } }) ~~~ 代码详情 ~~~ <loading hidden="{{show}}"></loading> <view class="cont"> <block wx:for="{{list}}" wx:key="index"> <view class="content"> <!-- <view>{{item.images.small}}</view> --> <image src="{{item.images}}" /> <view class="pf">{{item.title}}</view> <text>评分:{{item.average}}</text> </view> </block> </view> /**index.wxss**/ .cont image{ width: 200rpx; height: 280rpx; margin-bottom: 10rpx; } .cont{ display: flex; flex-wrap: wrap; justify-content:space-around; } .pf{ font-size: 30rpx; width: 200rpx; overflow: hidden; text-overflow:ellipsis; white-space: nowrap; } .cont text{ font-size: 27rpx; opacity: .7; } .content{ margin-bottom: 25rpx; text-align: left; } ~~~