https://www.cnblogs.com/lxz-blogs/p/12599475.html
[TOC]
## pages.json 設置對應頁面,激活下拉
> 設置enablePullDownRefresh屬性,即可激活
~~~
{
"path": "pages/pull_down/index",
"style": {
"navigationBarTitleText": "上拉下拉測試",
"enablePullDownRefresh":true
}
}
~~~
## 代碼測試
> 需要用到的生命周期有:
> 1. onLoad
> 2. onPullDownRefresh
> 3. onReachBottom
~~~
<template>
<view>
<view v-for="(item,index) of newList" :key="index" class="newList">
{{item}}
</view>
<view class="loading">{{loadingTxt}}</view>
</view>
</template>
<script>
let page=1,timer=null
export default {
data() {
return {
newList:[],
isTheLastPage:false,
loadingTxt:'加載更多'
}
},
onLoad(e) {
this.getInitNews()
},
onPullDownRefresh() {
//下拉的生命周期
this.getInitNews()
},
onReachBottom() {
//阻止重復加載
if(timer !== null){
clearTimeout(timer)
}
timer=setTimeout(()=>this.getMoreNews(),500)
// this.getMoreNews()
},
methods: {
//下拉刷新事件
getInitNews(){
page=1
//標題讀取樣式激活
uni.showNavigationBarLoading()
uni.request({
url:'https://demo.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=List1&page=1',
success: (res) => {
this.newList=res.data.split('--hcSplitor--')
//停止下拉樣式
uni.stopPullDownRefresh();
//隱藏標題讀取
uni.hideNavigationBarLoading();
this.isTheLastPage = false;
page++
}
})
},
//加載更多的新聞
getMoreNews(){
if (this.isTheLastPage) return;
this.loadingTxt='加載中'
uni.showNavigationBarLoading()
uni.request({
url:'https://demo.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=List1&page='+page,
success: (res) => {
if(res.data===null){
this.loadingTxt="已經加載全部";
//隱藏標題讀取
uni.hideNavigationBarLoading();
this.isTheLastPage = true;
return
}
this.newList=this.newList.concat(res.data.split('--hcSplitor--'))
// this.newList=[...this.newList,res.data.split('--hcSplitor--')]
//停止下拉樣式
uni.stopPullDownRefresh()
//隱藏標題讀取
uni.hideNavigationBarLoading()
page++
}
})
},
}
}
</script>
<style>
.newList{line-height: 2em;padding: 20px;}
.loading{line-height: 2em;text-align: center;color: #888;margin-top: 30rpx;}
</style>
~~~
- 基礎知識
- UNI核心介紹
- flex布局
- 生命周期
- 全局方法
- 組件定義
- 自定義組件
- 全局組件
- 組件之間的數據傳輸
- 條件編譯
- 自定義頭部
- 節點信息 (SelectorQuery)
- vuejs基礎語法
- 頁面跳轉以及參數傳遞
- 事件的監聽注冊以及觸發
- css3動畫
- block的妙用
- mixin (混入)
- uniapp快捷鍵
- vuex狀態管理
- 實用功能
- 獲取服務提供商
- 啟動頁 / 啟動界面
- 引導頁
- tabbar配置
- 頭部導航欄基礎設置
- 上拉下拉(刷新/加載)
- 第三方登錄
- 第三方分享
- 推送通知 之 unipush
- scroll-view雙聯動
- 配置iOS通用鏈接(Universal Links)
- 本地緩存操作
- 升級/更新方案
- 熱更新
- 圖片上傳
- 搜索頁實現
- canvas繪圖助手
- 地圖定位
- 第三方支付————todo
- 分類輪播
- 清除應用緩存
- uniapp與webview的實時通訊
- 視頻-----todo
- 聊天----todo
- 長列表swiper左右切換
- 第三方插件
- uview
- mescroll
- uCharts (圖表)
- 無名 (更新插件)
- 第三方模版
- 自定義基座
- 打包發行
- 要封裝的方法
- 緩存 cache.js
- 請求接口 request.js
- 工具類 util.js
- 小程序登錄 xcxLogin.js
- 版本更新 update.js
- 優質插件
- 更新插件----todo
- 語音
- 語音識別 (含上傳)
- 百度語音合成播報接口
- 官方常用組建
- input 輸入框
- image 圖片
- audio 音頻
- picker 選擇器
- video 視頻
- scroll-view 滾動視圖