Swipe横滑与SwipeItem自定义横滑相互影响

背景

vue项目,H5页面,使用vant的组件库轮播组件<Swipe>,UI交互要求,在每个SwipeItem中有内容,可自横滑,查看列表内容

核心代码

html 复制代码
<template>
  <Swipe
    class="my_swipe"
    :autoplay="3000"
    indicator-color="#9d9d9d"
    :stop-propagation="false"
    :show-indicators="false"
    @change="onChange"
  >
    <SwipeItem v-for="(item, index) in activeList" :key="item.activityId" class="swipe_item">
      <div class="activity-container">
        <StairNewUserBanner
          v-if="item.taskScene === SCENE.NEWUSER || item.taskScene === SCENE.REUNION"
          :banner-data="item"
          @jumpPage="jumpToActivePage"
        />
        <ProgressCard
          v-else
          :card-data="item"
          :card-index="index"
          @join="clickJoin(item, index)"
          @jumpPage="jumpToActivePage"
        />
      </div>
    </SwipeItem>
  </Swipe>
</template>
html 复制代码
<template>
  <div class="stair-new-user-banner-container">
    <div class="top" :style="topStyle" @click="jumpPage">
      <template v-if="!isCustomImg">
        <div class="title">
          <div class="left">{
  
  { topTitle }}</div>
          <div v-if="topTitle2" class="right">·</div>
          <div class="right">{
  
  { topTitle2 }}</div>
          <img class="arrow" src="https://www.baidu.com/" />
        </div>
        <div class="desc">
          <div v-if="showActivityRemindTime" class="remind-time">
            距结束
            <div v-if="activityRemindTime.days !== '00'" class="time-item">
              <div class="num">{
  
  { activityRemindTime.days }}</div>
              天
            </div>
            <div v-if="activityRemindTime.hours !== '00'" class="time-item">
              <div class="num">{
  
  { activityRemindTime.hours }}</div>
              小时
            </div>
            <div v-if="activityRemindTime.minutes !== '00' && activityRemindTime.days === '00'" class="time-item">
              <div class="num">{
  
  { activityRemindTime.minutes }}</div>
              分钟
            </div>
          </div>
          <div class="line"></div>
          <div>{
  
  { activityBizTypeDesc }}</div>
        </div>
      </template>
    </div>
    <div ref="bannerContent" class="content">
      <div class="crisp">
        <BannerSection
          v-for="(item, index) in sectionList"
          :key="index"
          :section-data="item"
          :static-data="staticData"
          :section-list="sectionList"
          :index="index"
        />
        <div class="bottom-bar">
          <div class="process-bar" :style="processBarStyle"></div>
        </div>
      </div>
    </div>
  </div>
</template>

问题描述

当想要滚动sectionList的内容时,SwipeItem跟着一起横滑

问题原因

sectionList列表的横滑事件冒泡了,影响到了轮播的横滑

解决方案

javascript 复制代码
  mounted() {
    this.handleTouchMove = (e) => {
      e.stopPropagation()
    }
    this.handleTouchStart = (e) => {
      e.stopPropagation()
    }
    this.$refs.bannerContent.addEventListener('touchmove', this.handleTouchMove)
    this.$refs.bannerContent.addEventListener('touchstart', this.handleTouchStart)
  },
  beforeDestroy() {
    this.$refs.bannerContent.removeEventListener('touchmove', this.handleTouchMove)
    this.$refs.bannerContent.removeEventListener('touchstart', this.handleTouchStart)
  }

fix

小程序的swiper组件和每个swiper-item中用<scroll-view class="content" scroll-x="{ {true}}"></scroll-view>包裹的横滑没有这个问题

相关推荐
小兵张健7 小时前
价值1000的 AI 工作流:Codex 通用前端协作模式
前端·aigc·ai编程
sunny_7 小时前
面试踩大坑!同一段 Node.js 代码,CJS 和 ESM 的执行顺序居然是反的?!99% 的人都答错了
前端·面试·node.js
拉不动的猪8 小时前
移动端调试工具VConsole初始化时的加载阻塞问题
前端·javascript·微信小程序
ayqy贾杰9 小时前
Agent First Engineering
前端·vue.js·面试
IT_陈寒10 小时前
SpringBoot实战:5个让你的API性能翻倍的隐藏技巧
前端·人工智能·后端
iceiceiceice10 小时前
iOS PDF阅读器段评实现:如何从 PDFSelection 精准还原一个自然段
前端·人工智能·ios
大金乄10 小时前
封装一个vue2的elementUI 表格组件(包含表格编辑以及多级表头)
前端·javascript
葡萄城技术团队11 小时前
【性能优化篇】面对万行数据也不卡顿?揭秘协同服务器的“片段机制 (Fragments)”
前端
程序员阿峰11 小时前
2026前端必备:TensorFlow.js,浏览器里的AI引擎,不写Python也能玩转智能
前端
Jans11 小时前
Shipfe — Rust 写的前端静态部署工具:一条命令上线 + 零停机 + 可回滚 + 自动清理
前端