### 將請求函數封裝實現瀑布流
~~~
//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;
}
~~~
- 前期準備
- 軟件安裝配置
- 語法 以及 功能 的實現
- 小程序中的 輪播
- 翻轉輪播
- 實現 跳轉 頁面
- 詳談 跳轉頁面
- for 循環 渲染 頁面(重點)
- 點擊 改變 元素內容
- 功能 封裝(創建、使用 模板)(重點)
- js模塊化(重點)
- if-else實現 三目運算
- 底部導航欄tabBar 實現
- 小程序中的 函數調用 方法
- 小程序中的 block 包裹元素
- 小程序中的 hover事件
- import 標簽(重點)
- 其他
- 在本地模擬接口取數據
- 點擊跳轉 并將該元素的id一起傳遞給跳轉的頁面
- 點擊詳情頁顯示
- 點擊事件(bindtap/catchtap)
- 圖片的mode屬性
- 跳轉頁面時實現頂部顯示頁面標題
- hello world
- 將豆瓣服務器接口設置在本地
- 組件
- 地圖
- 下拉刷新
- 數據加載 loading...
- 動態設置導航(title設置)
- 實現js代碼的模塊化
- 傳參
- 組件中的生命周期函數
- 實戰
- 發送http請求
- 可用的豆瓣接口
- 處理豆瓣列表頁的數據
- 從接口上取數據渲染到頁面上1
- 從接口上取數據渲染頁面實現瀑布流2
- 瀑布流
- 音樂播放
- 文章詳情頁
- 音樂播放組件
- 音樂播放 最終版
- 電影(封裝取數據渲染)
- 分享與收藏
- 搜索框
- 將電影列表數據放緩存
- 零碎知識點
- 談組件
- 請求封裝 (重點)
- 實現簡單需求的請求失敗的封裝
- 使用class實現顯示各種錯誤信息
- 再次封裝帶class的請求實現改變里面給的url
- 使用promise 封裝http
- promise
- generator
- 01.介紹
- 02. 基本
- 03. 實例
- 04.yield
- asyns
- 01. 介紹
- 02. 使用
- 03. 取豆瓣
- 子組件(模板文件)接收父組件傳來的參數并改變其值
- 模塊化
- 在模板中提取相同的部分behavior
- 字符串與數組之間的轉換
- 子組件向父組件傳參
- 談 triggerEvent
- 整體展示
- 父組件向子組件傳wxml (在兩個組件比較相似的情況 定義卡 槽傳 wxml)
- 傳css (在父組件中定義子組件的樣式)
- 使用wxs給wxml傳js
- 點贊
- 小程序中的正則
- 組件中實現下拉刷新
- 用戶授權
- 組件點擊圖片獲取信息
- 說明
- 小程序上下滑動