zoukankan      html  css  js  c++  java
  • uni-app 下拉刷新 上拉加载

    首先在page页面设置enablePullDownRefresh属性  激活下拉

    {
                "path": "pages/index/index",
                "style": {
                    "navigationBarTitleText": "uni-app",
                    "enablePullDownRefresh":true
                }
            }

    index.vue

    <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:[],
                    loadingTxt:'加载更多'
                }
            },
            onLoad(e) {
                this.getNews()
            },
            onPullDownRefresh() {
                //下拉的生命周期
                this.getNews()
            },
            onReachBottom() {
                //阻止重复加载
                if(timer !== null){
                    clearTimeout(timer)
                }
                timer=setTimeout(()=>this.getMoreNews(),500)
                // this.getMoreNews()
            },
            methods: {
                //下拉刷新事件
                getNews(){
                    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()
                            page++
                        }
                    })
                },
                //加载更多的新闻
                getMoreNews(){
                    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="已经加载全部"
                                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>
  • 相关阅读:
    [P4721] 【模板】分治 FFT
    [GYM102452E] Erasing Numbers
    [LOJ6220] sum
    [CF776B] Sherlock and His Girlfriend
    [LOJ6087] 毒瘤题
    [LOJ2612] 花匠
    [LOJ529] 自然语言
    [CTSC2017] 吉夫特
    [LOJ6671] EntropyIncreaser 与 Minecraft
    [LOJ3196] 挂架
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/12599475.html
Copyright © 2011-2022 走看看