uni-app 上拉加载跳转页面

上拉触底生命周期:onReachBottom
具体实现:
模拟加载组件:

<template>
    <view class="uni-load-more">
        <view v-show="status === 'loading' && showIcon" class="uni-load-more__img">
            <view class="load1 load">
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
            </view>
            <view class="load2 load">
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
            </view>
            <view class="load3 load">
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
                <view :style="{ background: color }" class="uni-load-view_wrapper" />
            </view>
        </view>
        <text :style="{ color: color }" class="uni-load-more__text">
            {{ status === 'more' ? contentText.contentdown : status === 'loading' ? contentText.contentrefresh : contentText.contentnomore }}
        </text>
    </view>
</template>
<script>
    export default {
        name: 'UniLoadMore',
        props: {
            status: {
                // 上拉的状态:more-loading前;loading-loading中;noMore-没有更多了
                type: String,
                default: 'more'
            },
            showIcon: {
                type: Boolean,
                default: true
            },
            color: {
                type: String,
                default: '#777777'
            },
            contentText: {
                type: Object,
                default () {
                    return {
                        contentdown: '上拉显示更多',
                        contentrefresh: '正在加载...',
                        contentnomore: '没有更多数据了'
                    }
                }
            }
        }
    }
</script>

<style>
    @charset "UTF-8";

    .uni-load-more {
        display: flex;
        flex-direction: row;
        height: 80upx;
        align-items: center;
        justify-content: center
    }
    .uni-load-more__text {
        font-size: 20rpx;
        color: #333333;
        font-family: 'DINOT-REGULAR';
    }
    .uni-load-more__img {
        height: 24px;
        width: 24px;
        margin-right: 10px
    }
    .uni-load-more__img>.load {
        position: absolute
    }
    .uni-load-more__img>.load .uni-load-view_wrapper {
        width: 6px;
        height: 2px;
        border-top-left-radius: 1px;
        border-bottom-left-radius: 1px;
        background: #999;
        position: absolute;
        opacity: .2;
        transform-origin: 50%;
        animation: load 1.56s ease infinite
    }
    .uni-load-more__img>.load .uni-load-view_wrapper:nth-child(1) {
        transform: rotate(90deg);
        top: 2px;
        left: 9px
    }

    .uni-load-more__img>.load .uni-load-view_wrapper:nth-child(2) {
        transform: rotate(180deg);
        top: 11px;
        right: 0
    }
    .uni-load-more__img>.load .uni-load-view_wrapper:nth-child(3) {
        transform: rotate(270deg);
        bottom: 2px;
        left: 9px
    }
    .uni-load-more__img>.load .uni-load-view_wrapper:nth-child(4) {
        top: 11px;
        left: 0
    }
    .load1,
    .load2,
    .load3 {
        height: 24px;
        width: 24px
    }
    .load2 {
        transform: rotate(30deg)
    }
    .load3 {
        transform: rotate(60deg)
    }
    .load1 .uni-load-view_wrapper:nth-child(1) {
        animation-delay: 0s
    }
    .load2 .uni-load-view_wrapper:nth-child(1) {
        animation-delay: .13s
    }
    .load3 .uni-load-view_wrapper:nth-child(1) {
        animation-delay: .26s
    }
    .load1 .uni-load-view_wrapper:nth-child(2) {
        animation-delay: .39s
    }
    .load2 .uni-load-view_wrapper:nth-child(2) {
        animation-delay: .52s
    }
    .load3 .uni-load-view_wrapper:nth-child(2) {
        animation-delay: .65s
    }

    .load1 .uni-load-view_wrapper:nth-child(3) {
        animation-delay: .78s
    }

    .load2 .uni-load-view_wrapper:nth-child(3) {
        animation-delay: .91s
    }
    .load3 .uni-load-view_wrapper:nth-child(3) {
        animation-delay: 1.04s
    }
    .load1 .uni-load-view_wrapper:nth-child(4) {
        animation-delay: 1.17s
    }
    .load2 .uni-load-view_wrapper:nth-child(4) {
        animation-delay: 1.3s
    }

    .load3 .uni-load-view_wrapper:nth-child(4) {
        animation-delay: 1.43s
    }
    @-webkit-keyframes load {
        0% {
            opacity: 1
        }

        100% {
            opacity: .2
        }
    }
</style>

引用:

<uni-load-more :status="status" :color="loadingcolor" :content-text="contentText" v-if="loading"/>

import uniLoadMore from '../../component/uni-load-more.vue'

data() {
    return {
        status:'',
        loadingcolor:'#006B69',
        contentText: {
            contentrefresh: '',
            contentnomore: 'Reached the bottom of the page, pull up to load the next page'
        },
        loading:false,
        toustrart:0,
        touend:0,
        bottoms:false,
        bot:false
    }
},

components:{
    uniLoadMore
}

上拉加载,跳转下一页实现:

第一步:触底时,给一个提示,到达页面底部

onReachBottom(){
    this.loading=true
    this.status='noMore'
    this.loadingcolor="#777777";
    this.bottoms = true;
    console.log('onreachbottom')
},

第二步:实现上拉,主要利用手指进行上拉动作时,开始和结束的距离判断
具体实现:

touchstart(event){
    this.toustrart = event.touches[0].clientY
},
touchmove(event){
    let  tag = event.touches;
    this.touend = tag[0].clientY
},
touchend(){
        if(this.toustrart - this.touend < 0){
        this.bottoms = false
    }
    if(this.bottoms){
        if(this.toustrart - this.touend > 50){
            this.loading=true
            this.status='loading'
            this.loadingcolor="#777777";
            var self = this
            setTimeout(function(){
                uni.navigateTo({
                     url: '../points/points'
                });
                self.status = 'noMore'
            },1000)
        }
    }
                
}

第三步,页面初始化时,给this.toustrart 和 this.touend清零,防止返回时还存在,点击就能跳转

onShow() {
    this.toustrart = 0;
    this.touend = 0;
},
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容