• 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>
  • 相关阅读:
    Visual Detection of Lintel-Occluded Doors from a Single Image
    Linux下快速构建Android编译环境
    How to Train YOLOv4 on a Custom Dataset
    yolo v4 darknet colab
    Deep Image Matting
    给 MSYS2 添加中科大的源
    msys2 mingw64 ffmpeg 搭建最新ffmpeg编译环境 可用 ffmpeg 4.1 及更新版本
    GB28181对接摄像机/NVR视频流
    video.js在iframe中如何解决无法自动播放问题
    LiveGBS-摄像机网页低延时无插件直播实现
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/12599475.html
Copyright © 2020-2023  润新知