伦理片hd-伦理片 在线播放-伦理片 在线-伦理免费在线观看-综合图片区-综合婷婷

訂閱本欄目 RSS您所在的位置: 深山工作室 > uni-app > 正文

uni-app實現上拉加載,下拉刷新(下拉帶動畫)

2020/9/15 15:20:52 字體: 瀏覽 7831

直接展示代碼,uni-app的上拉加載動畫

1 . 在pages.json添加允許下拉刷新
    {
        "path":"pages/lookuser/lookuser",
        "style":{
            "navigationBarTitleText":"用戶日志",
            "enablePullDownRefresh": true//就是這個
        }
    }


2. 上拉加載更多組件
比如把組件放在component下了component/uni-load-more.vue


<template>
<view class="load-more">
<view class="loading-img" v-show="loadingType === 1 && showImage">
<view class="load1">
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
</view>
<view class="load2">
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
</view>
<view class="load3">
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
<view :style="{background:color}"></view>
</view>
</view>
<text class="loading-text" :style="{color:color}">
{{loadingType === 0 ? contentText.contentdown : (loadingType === 1 ? contentText.contentrefresh : contentText.contentnomore)}}</text>
</view>
</template>

<script>
export default {
name: "load-more",
props: {
loadingType: {
//上拉的狀態:0-loading前;1-loading中;2-沒有更多了
type: Number,
default: 0
},
showImage: {
type: Boolean,
default: true
},
color: {
type: String,
default: "#777777"
},
contentText: {
type: Object,
default () {
return {
contentdown: "上拉顯示更多",
contentrefresh: "正在加載...",
contentnomore: "沒有更多數據了"
};
}
}
},
data() {
return {}
}
}
</script>

<style>
.load-more{display:flex;flex-direction:row;height:80upx;align-items:center;justify-content:center;}
.loading-img{height:24px;width:24px;margin-right:10px;}
.loading-text{font-size:28upx;color:#777777;}
.loading-img>view{position:absolute;}
.load1,.load2,.load3{height:24px;width:24px;}
.load2{transform:rotate(30deg);}
.load3{transform:rotate(60deg);}
.loading-img>view view{width:6px;height:2px;border-top-left-radius:1px;border-bottom-left-radius:1px;background:#777;position:absolute;opacity:0.2;transform-origin:50%;-webkit-animation:load 1.56s ease infinite;}
.loading-img>view view:nth-child(1){transform:rotate(90deg);top:2px;left:9px;}
.loading-img>view view:nth-child(2){-webkit-transform:rotate(180deg);top:11px;right:0px;}
.loading-img>view view:nth-child(3){transform:rotate(270deg);bottom:2px;left:9px;}
.loading-img>view view:nth-child(4){top:11px;left:0px;}
.load1 view:nth-child(1){animation-delay:0s;}
.load2 view:nth-child(1){animation-delay:0.13s;}
.load3 view:nth-child(1){animation-delay:0.26s;}
.load1 view:nth-child(2){animation-delay:0.39s;}
.load2 view:nth-child(2){animation-delay:0.52s;}
.load3 view:nth-child(2){animation-delay:0.65s;}
.load1 view:nth-child(3){animation-delay:0.78s;}
.load2 view:nth-child(3){animation-delay:0.91s;}
.load3 view:nth-child(3){animation-delay:1.04s;}
.load1 view:nth-child(4){animation-delay:1.17s;}
.load2 view:nth-child(4){animation-delay:1.30s;}
.load3 view:nth-child(4){animation-delay:1.43s;}
@-webkit-keyframes load{0%{opacity:1;}
100%{opacity:0.2;}
}
</style>

3. 在頁面上調用組件


<template>
    <view style="flex: 1;">
<view v-for="(item, index) in newsList" class="newslist">{{item}}</view>
<!--3使用組件 -->
<uni-load-more  :loadingType="loadingType" :contentText="contentText" ></uni-load-more>
</view>
</template>

<script>
//1引入組件 uni-load-more.vue
import uniLoadMore from '../../component/uni-load-more.vue';

var _self,
page = 1,
timer = null;
// 定義全局參數,控制數據加載

export default {
    components: {//2注冊組件
        uniLoadMore
    },
    data: {
        newsList: [],
        loadingText: '加載中...',
        loadingType: 0,//定義加載方式 0---contentdown  1---contentrefresh 2---contentnomore
        contentText: {
            contentdown:'上拉顯示更多',
            contentrefresh: '正在加載...',
            contentnomore: '沒有更多數據了'
        }
    },
    onLoad: function() {
        _self = this;
//頁面一加載時請求一次數據
        this.getnewsList();
    },
    onPullDownRefresh: function() {
//下拉刷新的時候請求一次數據
        this.getnewsList();
    },
    onReachBottom: function() {
//觸底的時候請求數據,即為上拉加載更多
//為了更加清楚的看到效果,添加了定時器
        if (timer != null) {
            clearTimeout(timer);
        }
        timer = setTimeout(function() {
            _self.getmorenews();
        }, 1000);

// 正常應為:
// _self.getmorenews();
    },
    methods: {
        getmorenews: function() {
            if (_self.loadingType !== 0) {//loadingType!=0;直接返回
                return false;
            }
            _self.loadingType = 1;
            uni.showNavigationBarLoading();//顯示加載動畫
            uni.request({
                url:'https://demo.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=list1&page=' + page,
                method: 'GET',
                success: function(res) {
                    console.log(JSON.stringify(res));
                    if (res.data == null) {//沒有數據
                        _self.loadingType = 2;
                        uni.hideNavigationBarLoading();//關閉加載動畫
                        return;
                    }
                    page++;//每觸底一次 page +1
                    _self.newsList = _self.newsList.concat(res.data.split('--hcSplitor--'));//將數據拼接在一起
                    _self.loadingType = 0;//將loadingType歸0重置
                    uni.hideNavigationBarLoading();//關閉加載動畫
                }
            });
        },
        getnewsList: function() {//第一次回去數據
            page = 1;
            this.loadingType = 0;
            uni.showNavigationBarLoading();
            uni.request({
                url: 'https://demo.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=list1&page=1',
                method: 'GET',
                success: function(res) {
                    page++;//得到數據之后page+1
                    _self.newsList = res.data.split('--hcSplitor--');
                    uni.hideNavigationBarLoading();
                    uni.stopPullDownRefresh();//得到數據后停止下拉刷新
                }
            });
        }
    }
};
</script>
<style>
.newslist{padding:10px;line-height:60px;font-size:28px;}
.loading{text-align:center;line-height:80px;}
</style>


直接復制過去就能調用了,趕快試試吧

來源地址:https://blog.csdn.net/qq_39197547/article/details/84832913

后一頁:沒有了
相關閱讀
特別簡潔的簡單JavaScript日歷及說明
純div+css制作的彈出菜單-02
CSS布局實例:上中下三行,中間自適應
熟記ASP+Access數據庫的18條安全法則
針對table,div隔行變色的JS方法
用Javascript仿flash焦點圖片效果支持IE與火狐
cookies
如何購買深山旅行社管理系統?
共有0條關于《uni-app實現上拉加載,下拉刷新(下拉帶動畫)》的評論
發表評論
正在加載評論......
返回頂部發表評論
呢 稱:
表 情:
內 容:
評論內容:不能超過 1000 字,需審核,請自覺遵守互聯網相關政策法規。
驗證碼: 驗證碼 
網友評論聲明,請自覺遵守互聯網相關政策法規。

您發布的評論即表示同意遵守以下條款:
一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
三、本站對您所發布內容擁有處置權。

更多信息>>欄目類別選擇
百度小程序開發
微信小程序開發
微信公眾號開發
uni-app
asp函數庫
ASP
DIV+CSS
HTML
python
更多>>同類信息
uni-app開發表單input組件的一些規則說明自己預留使用
uni-app:使用uni.downloadFile下載word或pdf文件并保存到手機
小程序中利用addPhoneContact將聯系人的信息添加到手機通訊錄支持保存聯系人頭像
微信小程序打開客服提示:該小程序提供的服務出現故障,請稍后重試
微信小程序客服會話只能過button讓用戶主動觸發
uni-app開發微信小程序使用button的open-type為contact調用微信客服不能用view或者js調用
更多>>最新添加文章
dw里面查找替換使用正則刪除sqlserver里面的CONSTRAINT
Android移動端自動化測試:使用UIAutomatorViewer與Selenium定位元素
抖音直播音掛載小雪花 懂車帝小程序
javascript獲取瀏覽器指紋可以用來做投票
火狐Mozilla Firefox出現:無法載入您的Firefox配置文件 它可能已經丟失 或是無法訪問 問題解決集合處理辦法
在Android、iOS、Windows、MacOS中微信小程序的文件存放路徑
python通過代碼修改pip下載源讓下載庫飛起
python里面requests.post返回的res.text還有其它的嗎
更多>>隨機抽取信息
div+css黑色焦點圖(幻燈片效果非常 不錯)
asp防止access數據庫被下載破解
Appium元素定位方式之android_uiautomator定位
JS操作Cookie記錄
專業地接服務的旅行社建站解決方案
如何提高網站的PR值
主站蜘蛛池模板: 日本视频www色变态 日本视频www色 | 手机看片日韩日韩 | 天堂网在线最新版官网 | 男女那啥的视频免费 | 久久精品国产72国产精福利 | 国产成人福利在线视老湿机 | 欧美自拍偷拍视频 | 内地精品露脸自拍视频香蕉 | 欧美日韩国产精品自在自线 | 亚洲 欧美 91| 欧美三级蜜桃2在线观看 | 国产成人精品福利网站在线 | 香蕉视频国产在线观看 | 亚洲日本中文字幕在线 | 亚洲综合激情六月婷婷在线观看 | 女人18毛片一级毛片在线 | 亚洲欧美一区二区三区在线播放 | 亚洲一二三四 | 国产亚洲欧美成人久久片 | 亚洲一区毛片 | 日韩一级欧美一级在线观看 | 亚洲小视频| 日本在线视频一区 | 欧美色婷婷| 韩国美女爽快一级毛片黄 | 天天摸天天舔天天操 | 自拍偷拍亚洲第一页 | 日产精品一卡2卡三卡4乱码久久 | 母性本能| 国产精品女在线观看 | 国内外成人免费在线视频 | 99综合在线 | 四虎成人免费大片在线 | 免费中文字幕一级毛片 | 成人午夜爽爽爽免费视频 | 日本色播 | 天天干视频网 | 岛田阳子五十路在线观看 | 久久成人亚洲 | 亚洲欧美日本国产一区二区三区 | 大香线蕉97久久 |