【bug】scroll-view内元素bindlongpress无效
发布于 4 年前 作者 jun28 15500 次浏览 来自 问答

scroll-view在设置了scroll-y以及scroll-into-view之后,每次数据增加就自动滚动到最后一个item,item设置bindlongpress,自动滚动停止以后,长按item无法触发监听事件;当手动滚动scroll-view内部之后,长按item可以触发监听事件,demo代码:

<scroll-view class=“scroll_view” scroll-into-view="{{scrollIntoView}}" scroll-y>

    <view

        wx:for="{{scrollList}}"

        wx:key="{{item.id}}"

        bindlongpress=“longpress”

        id=“item_{{item.id}}”

        class=“item”

    >

        {{item.cnt}}

    </view>

</scroll-view>

Page({

    data: {

        scrollList: [],

        scrollIntoView: ‘’

    },

    onReady() {

        this.startTestScroll();

    },

    startTestScroll() {

        const that = this;

        const { scrollList } = this.data;

        

        const time = new Date().getTime();

        const item = {

            id: time,

            cnt: time

        };

        

        scrollList.push(item);

        that.setData({

            scrollList,

            scrollIntoView: ‘item_’ + item.id

        });

        

        if (scrollList.length < 10) {

            setTimeout(() => {

                that.startTestScroll();

            }, 600);

        }

    },

    longpress() {

        wx.showToast({

            title: ‘长按成功!’

        });

    }

})

10 回复

longpress真的很重要,官方想办法解决下这个问题吧

在近期版本(预计是2.1.0)里会针对滚动结束后的长按进行改进。

我的也是 没在scroll-view里也bindlongpress偶尔失效 需要手动动一下页面

为啥这么多人有这个问题 官方就没人来解答一下呢

官方能不能负责任一点?

确实会偶尔失效

我也是,真机(iphone 7 plus),最新wechat,普通的view,longpress偶尔无法触发。

没人解决吗

认认真真地写好了demo,都是花了时间的,发完也没有人理一下?

不仅是scrow-view. 我在普通view里的bindlongpress再模拟器上正常, 在真机上就无效了. 环境跟你一样.

为什么我发的每个贴都能沉了?

回到顶部