w***@126.com
w***@126.com
  • 发布:2019-08-22 17:21
  • 更新:2021-04-09 10:32
  • 阅读:4244

点击mescroll-uni 组件里的任何元素 都会请求一次upCallback 这是为什么呢?

分类:uni-app
<template>  
    <view class="content">  

        <!--        <view class="status_bar" :style="style">  

        </view>  
        <view class="status_bar-con">  

        </view> -->  

        <!-- 浅记列表首页 -->  
        <view class="top_nav">  
            <text @tap="changeTab(0)" :class="{active:tabType==0}" class="top_nav_title">最新</text>  
            <text @tap="changeTab(1)" :class="{active:tabType==1}" class="top_nav_title">热门</text>  
        </view>  

        <view class="qj_list">  
            <mescroll-uni top="96" @down="downCallback" @up="upCallback" @init="mescrollInit">  
                <view class="qj_item" v-for="(item,index) in list" :key="index">  
                    <view class="qj_item_user">  
                        <view class="qj_item_user-left" @tap="goPersonal(item.diary.user.user_id)">  
                            <image :src="item.diary.user.avtar" class="qj_item_user-img" mode=""></image>  
                            <view class="qj_item_user-info">  
                                <text> {{item.diary.user.nickname}} </text>  
                                <text> {{item.diary.modify_time}} </text>  
                            </view>  
                        </view>  
                        <view @tap="showMore" class="iconfont icon-gengduo">  
                        </view>  
                    </view>  

                    <view class="qj_item_content">  
                        <view @tap="goDetail(item.diary)" class="qj_say">  
                            <text> {{item.diary.content}} </text>  
                        </view>  
                        <app-pic :imgs="item.diary.imgs"></app-pic>  
                    </view>  

                    <app-single-item :diary_obj="item.diary"></app-single-item>  

                </view>  
            </mescroll-uni>  

        </view>  
        <app-share></app-share>  
        <app-complain></app-complain>  
        <image @tap="imagePreview(0)" v-if="diary.imgs.length == 1" class="qj_pic" :src="diary.imgs[0].img_url" mode="aspectFill"></image>  

    </view>  
</template>  

<script>  
    import Pic from '@/components/pic/pic.vue'  
    import SingleItem from '@/components/single_item/single_item.vue'  
    import MescrollUni from '@/components/mescroll-uni/mescroll-uni.vue';  
    import Share from '@/components/share/share.vue'  
    import Complain from '@/components/complain/complain.vue'  
    import {  
        getHeader,  
        isLogin  
    } from '@/common/util';  
    export default {  
        data() {  
            return {  
                mescroll: null, //mescroll实例对象  
                tabType: 0, //  0:最新 1 热门   
                list: [],  
                cur_time: (new Date()).valueOf()  

            }  
        },  
        components: {  
            MescrollUni,  
            appShare: Share,  
            appComplain: Complain,  
            appSingleItem: SingleItem,  
            appPic: Pic  
        },  
        onLoad() {  
            //检查用户是否已经登录  
            let loginRes = isLogin('/pages/index/index', 2);  
            if (!loginRes) {  
                return false;  
            }  

        },  
        computed: {  
            style() {  
                // #ifndef APP-PLUS  
                var systemInfo = uni.getSystemInfoSync()  
                return `height:${systemInfo.statusBarHeight}px`  
                // #endif  
                //#ifdef APP-PLUS  
                return ''  
                //#endif  
            }  
        },  
        methods: {  
            // mescroll组件初始化的回调,可获取到mescroll对象  
            mescrollInit(mescroll) {  
                this.mescroll = mescroll;  
            },  
            downCallback(mescroll) {  
                this.cur_time = (new Date()).valueOf();  
                mescroll.resetUpScroll();  
            },  
            upCallback(mescroll) {  
                if (!getHeader()) {  
                    return;  
                }  
                uni.request({  
                    url: this.apiQy + '/qqsmall/diary/searchDiary',  
                    method: 'POST',  
                    data: {  
                        p: mescroll.num - 1,  
                        rn: 10,  
                        order_type: this.tabType,  
                        order: 1,  
                        cur_time: this.cur_time  
                    },  
                    header: getHeader(),  
                    success: res => {  

                        res = res.data;  

                        if (res.return_code == 101) {  
                            this.tokenFail('/pages/index/index', 2);  
                            return;  
                        }  
                        if (res.return_code == 1) {  
                            if (mescroll.num == 1) this.list = [];  
                            this.list = this.list.concat(res.result.filter(item => item.type == 0));  
                            console.log(this.list);  

                            this.$nextTick(() => {  
                                mescroll.endSuccess(res.result.length)  
                            })  
                        } else {  
                            mescroll.endErr();  
                        }  
                    },  
                    fail: (error) => {  
                        console.log(error);  
                    },  
                    complete: () => {}  
                });  
            },  

            // 切换菜单  
            changeTab(type) {  
                if (this.tabType !== type) {  
                    this.tabType = type  
                    this.mescroll.resetUpScroll() // 刷新列表数据  
                }  
            },  
            goPersonal(userId) {  
                uni.navigateTo({  
                    url: '/pages/my/my?user_id=' + userId  
                })  
            }  

        }  
    }  
</script>  

<style>  
    page {  
        background-color: #F3E3E8;  

    }  

    .status_bar {  
        height: var(--status-bar-height);  
        width: 100%;  
    }  

    .status_bar-con {  
        width: 100%;  
        height: 120upx;  
        background-image: url(~@/static/tab/nav_bg.png);  
        background-size: 100% 100%;  
        background-repeat: no-repeat;  
    }  
</style>  
2019-08-22 17:21 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com

字节跳动报VM137:1 TypeError: this.mescroll.resetUpScroll is not a function

1***@qq.com

1***@qq.com

默认是对执行down 和 up的回调, 你在 :up="upOption" 中设置一下 upOption={auto:false} ,不让回调初始化后自动执行

  • 冷月i

    同,有解决办法吗?

    2021-06-21 09:28

该问题目前已经被锁定, 无法添加新回复