scroll-view的bindscrolltolower属性循环触发?
发布于 7 年前 作者 weitan 8042 次浏览 来自 问答

以前滚动到底部加载页面有没有问题 ,但是升级完开发工具后,发现滚动底部bindscrolltolower循环触发,IOS有类似问题 , android没有此问题,有人遇到过吗???

10 回复

我也遇到这样的问题,请问有人解决的么?不固定的触发

bindscrolltolower加判断是无用的,其实应该还是源代码里的设计缺陷,bindscroll事件触发的问题,动态给scroll-top值时,判断有问题,导致滚动条定位值出现变动

我也遇到这种问题了,怎么解决啊?

测试

<scroll-view  scroll-y="true" scroll-top="{{curScrollTop}}"  class="nav_scroll" style="height: {{scrollHeight}}px" bindscrolltolower="loadMore" bindscroll="scroll"> 

<block wx:for="{{raiTabs}}" wx:key="raiTab.id" wx:for-item="raiTab" wx:for-index="index"></block>

  </scroll-view>




//获取应用实例

var app = getApp()
var api = require('../../utils/api.js')
var action = require('./../../utils/action.js')
Page({
  // 页面初始数据
    data: {
        // nav 初始化
        curNavId: 1,
        articles: [],
        raiTabs: [],
        indexs: 0,
        type: "",
        alias: "",
        anShow: true,
        scrollTop: [],
        scrollHeight:0,
        loading: [],
        noMore: false,
        pageNum: 0,
        page: 0,
        params: {},
        curScrollTop: 0
    },
    onLoad:function(){
        wx.showToast({
            title: '加载中',
            icon: 'loading',
            duration: 10000
        })
        let tabsUrl = 'store/strategy/tabs?cityId=310100&addr=1';
        api.fetchGet(tabsUrl, {'r': 'article'}).then(res => {
            var that = this
            that.setData({
                raiTabs : res.data.items,
                alias : res.data.items.alias,
                type : res.data.items.type
            })
            that.data.type = res.data.items[0].type
            that.data.alias = res.data.items[0].alias           
            let scrollTop = []
            let loading = []
            for (let i = 0; i < this.data.raiTabs.length; i++) {
                scrollTop.push(0)
                loading.push(false)
                wx.removeStorage({           
                    key:'strategyData' + i,
                    success: function(res) {
                    }
                })
                wx.removeStorage({
                    key:'strategyPage' + i,
                    success: function(resp) {
                    }
                })
            }
            this.setData({
                scrollTop: scrollTop
            })
            this.getData()
        })
    },
    onShow () {
        wx.getSystemInfo( {
            success: ( res ) => {
                let top = 84 * res.windowWidth / 750
                this.setData({
                    scrollHeight: res.windowHeight - top
                })
            }
        })
    },
    // 请求数据加载
    getData: function() {
            var that = this
            var num = this.data.indexs
            //最新的接口数据
            if(that.data.type == 'collection'){
                let collectionUrl = 'store/strategy/collection?limit=20&addr=1'
                api.fetchGet(collectionUrl,{
                    page: that.data.pageNum,
                    alias: that.data.alias,
                    type: that.data.type,
                    r: 'article'
                }).then(res => {
                    wx.hideToast()
                    if (res.data.items.length === 0) {
                        this.setData({
                            noMore: true
                        })
                        wx.showToast({
                            title: '已加载全部',
                            icon: 'loading'
                        })
                    }
                    that.data.pageNum++
                    that.data.articles = that.data.articles.concat(res.data.items)
                    let lArr = this.data.loading
                    lArr[num] = false
                    this.setData({ 
                        loading: lArr,
                        page: that.data.pageNum,
                        articles : that.data.articles
                    })
                     //缓存数据
                    wx.setStorage({
                        key:'strategyData' + that.data.indexs,
                        data:that.data.articles
                    })
                    wx.setStorage({
                        key:'strategyPage' + that.data.indexs,
                        data:that.data.pageNum
                    })
                })
            }
        },
//标签切换
    switchTab (e) {
        if(this.data.indexs == e.currentTarget.dataset.index){return}
        for (let key in this.data.loading) {
            this.data.loading[key] = false
        }
        // let arr = this.data.scrollTop
        // let index = this.data.indexs
        // arr[index] = this.data.curScrollTop
        // this.setData({
        //     scrollTop: arr
        // })
        var n = e.currentTarget.dataset.index;
        let id = e.currentTarget.dataset.id;
        var rName = e.currentTarget.dataset.alias;
        var rType = e.currentTarget.dataset.type;
        this.setData({
            pageNum: 0,
            articles: [],
            alias: rName,
            type: rType,
            indexs: n
        })
        let lArr = this.data.loading
        lArr[n] = true
        this.setData({
            loading: lArr,
            noMore: false
        })
        var pageValue = wx.getStorageSync('strategyPage' + this.data.indexs)
        var dataValue = wx.getStorageSync('strategyData' + this.data.indexs)
        if(pageValue.length !== 0 || dataValue.length !== 0){
            let lArr = this.data.loading
            lArr[n] = false
            this.setData({
                loading: lArr,
                noMore: false
            })
            this.setData({
                articles: dataValue,
                pageNum: pageValue
            })
            var scrollTopNumber = this.data.scrollTop[n]
            setTimeout(() => {
                this.setData({
                    curScrollTop: scrollTopNumber
                })
            })
        }else{
            // this.setData({
            //     articles: this.data.articles,
            //     pageNum: this.data.pageNum
            // })
            this.getData()
        }
    },
    // 滚动事件
    scroll (event) {
    //  该方法绑定了页面滚动时的事件,记录当前的position.y的值,为了请求数据之后把页面定位到这里来。
        if (this.data.noMore||this.data.loading[this.data.indexs]) return
        this.setData({
            curScrollTop: event.detail.scrollTop
        })
        console.log(event.detail)
    },
    // 跳转至详情页
    navigateDetail: function(e){
        // wx.navigateTo({
        //     url:'../articalDetail/articalDetail?id=' + e.currentTarget.dataset.aid + 'r=strategyLis'
        // })
        let uri = e.currentTarget.dataset.uri
        action.uriAction(uri)
    },
    // 跳转至合集
    clickURI (e) {
        let uri = e.currentTarget.dataset.uri
        action.uriAction(uri)
    },
    // 加载更多
    loadMore: function (e) {
    // console.log(this.data.noMore)  
    // console.log(this.data.indexs)
    // console.log(this.data.loading[this.data.indexs])
        if (this.data.noMore||this.data.loading[this.data.indexs]) return
        let lArr = this.data.loading
            lArr[this.data.indexs] = true
        this.setData({
            loading: lArr
        })
        // if(this.data.loading[this.data.indexs]){
        // console.log(this.data.loading[this.data.indexs] + "23")
        wx.showToast({
            title: '加载中',
            icon: 'loading'
        })
        this.getData()   
        // }       
    }
})

我也遇到这种问题了,怎么解决啊?

    加判断不足以解决这个问题。

    事件是单线程处理的,加不加判断并不影响事件的处理(因为在一次处理完成后判断条件也就重置了),对这一问题需要另外的办法解决。

    以上问题解决后,本人又经过测试发现,在IOS中触底时,在一个触底事件未被处理时,在毫秒时间内会在事件队列中又产生一个触底事件。这就又需要另外的解决办法。

    针对以上两个问题本人均做出了解决方案,需要帮助的发我邮箱[email protected]

    

    

我也遇到了,多次触发,以前都是好的,希望官方赶紧修复。

只要超过lower-threshold就会触发,建议加个判断避免重复请求

对 ,以前是没问题的 我这里也是这样的  我就把动态定位滚动条给取消了  太恶心了

尤其是动态设置scroll-top,直接给你各种跳滚动条。<scroll-view  scroll-y=“true” scroll-top="{{curScrollTop}}"  class=“nav_scroll” style=“height: {{scrollHeight}}px” bindscrolltolower=“loadMore” bindscroll=“scroll”> 

回到顶部