vue3+ts+vant项目,实现可滑动的van-tabs+swiper的结合使用,如何在滑动swiper的图片时,禁止tabs滑动
一个项目要求van-tabs可以滑动切换,van-tabs里嵌套swiper轮播图,这时出现一个问题,当滑动swiper的时候,tabs也会跟着切换
使用@touchstart和@touchend事件来禁止tabs的滑动。在swiper组件上添加@touchstart.stop和@touchend.stop事件,阻止事件冒泡到van-tabs组件。示例代码如下:
<van-tabs v-model:active="active" animated sticky>
<van-tab title="1">
<swiper @touchstart.stop @touchend.stop>
<!-- swiper content -->
</swiper>
</van-tab>
</van-tabs>