Vant: swipe组件滑动时会触发item内的点击事件

Created on 29 May 2018  ·  19Comments  ·  Source: youzan/vant

What is the current behavior?
开启swipe 手势滑动时,滑动会同时触发内部自定义的点击事件

    <van-swipe v-if="selected===0" :autoplay="3000">
               <van-swipe-item v-for="(item,index) in bannerList" :key="index">
                            <img :src="item.picUrl" @click="goAdvert(item.type, item.skipName, item.id, item.shopId)" :alt="item.name">
                        </van-swipe-item>
               </van-swipe>

What is the expected behavior?
手势滑动时,不应同时触发内部点击

Which versions of Vant and Vue, and which browser / OS are affected by this issue? Did this work in previous versions of Vant?
"vant": "^1.1.3",
"vue": "^2.5.13",

Most helpful comment

image

All 19 comments

遇到了同样的问题 请问 是怎么解决的???

我的项目是由于使用了better-scroll和vant的swipe造成了冲突
解决方法:放弃使用vant的swipe组件,用better-scroll自己写一个滚动组件

我发现了 是因为我用了fastclick插件的问题, 不知道该如何解决,郁闷

解决了

怎么解决的 @xiaobingMa

@xiaobingMa 请问上如何解决的

fastclick

请问是如何解决的呢

image

同遇到这个问题

怎么解决 @有赞官方

同问,我改用了这个插件 vue-concise-slider

@Saber-tgb 我用另一个轮播组件,也遇到了同样的问题。首先想到的是touch事件禁止冒泡,禁止冒泡后可以解决滑动时触发的点击事件,但是轮播图本身的点击事件捕获不到了。。。。
解决方法是绑定俩个事件:
handleTouchMove(e) {
e.stopPropagation()
this.moved = true
}
handleTouchEnd(e) {
// 滑动时禁止冒泡,正常点击不会禁止
if (this.moved) {
this.moved = false
e.stopPropagation()
}
}

@zhuogx 我借用你的方法会将swipe-item的滚动都禁止了,然后我通过实现一个标志位可以解决
handleTouchMove() { this.moved = true; },
clickNoteItem() { if (this.moved === true) { this.moved = false; return; } },
只需要监听touchmove 和 click 就可以了

@jakietwo 这种方式在ios端会有问题,滑动后需要点击两下才能响应

@Saber-tgb 请问怎么解决的

我给Table组件加一个 :key="show", show 就是 控制Modal显示或隐藏的value

------------------ 原始邮件 ------------------
发件人: "ZhaoXiaoLin"notifications@github.com;
发送时间: 2019年8月27日(星期二) 上午10:06
收件人: "youzan/vant"vant@noreply.github.com;
抄送: "梧桐"392151426@qq.com; "Comment"comment@noreply.github.com;
主题: Re: [youzan/vant] swipe组件滑动时会触发item内的点击事件 (#1186)

@Saber-tgb 请问怎么解决的


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

为什么在touchmove时,用的是event.stopPropagation,而不是event.preventDefault();,导致拖动的过程中被触发click事件@chenjiahan

我也遇到这个问题,换成其它组件了

你们如果用vantUI建议看看vant官方文档 swiper组件文档有写
image

Was this page helpful?
0 / 5 - 0 ratings