当前位置: 首页 > article >正文

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

背景

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

核心代码

<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>
<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列表的横滑事件冒泡了,影响到了轮播的横滑

解决方案

  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>包裹的横滑没有这个问题


http://www.kler.cn/a/538393.html

相关文章:

  • Vue3 Ref全家桶详解:从入门到实战
  • Java数据结构 | TreeMap 和 TreeSet
  • G. Vlad and the Mountains
  • IDEA中Resolving Maven dependencies卡着不动解决方案
  • vscode中使用code-runner插件运行c程序语法报错code: 1
  • 基于大模型的围术期脆弱性评估系统研究报告
  • 双向链表、内核链表和gdb(20250208)
  • Linux之kernel(1)系统基础理论(1)
  • FreeRTOS的事件组
  • 协议-RK-Gstreamer
  • 07苍穹外卖之redis缓存商品、购物车(redis案例缓存实现)
  • 【Windows】PowerShell 缓存区大小调节
  • LMM-3DP:集成 LMM 规划器和 3D 技能策略实现可泛化操作
  • 深入剖析 JVM 垃圾收集器之 CMS 和 G1
  • Golang:精通sync/atomic 包的Atomic 操作
  • 本地计算机上的MySQL80服务启动后停止某些服务在未由其他服务或程序使用时将自动停止(不需要清除数据)
  • 今日写题work
  • Https握手过程 (面试题)
  • PMP–一、二、三模–分类–13.干系人管理
  • Python关键字全解析与实例应用
  • python Excel 表读取合并单元格以及清除空格符
  • #渗透测试#批量漏洞挖掘#微商城系统 goods SQL注入漏洞
  • JUnit 5 中获取测试类、测试方法及属性的注解
  • DeepSeek与Vue.js组件开发:解锁AI与前端开发的融合密码
  • 算法兵法全略(译文)
  • 低代码系统-插件功能分析( 某道云)