vue3的uniapp,左滑出现删除按钮

<template>
  <view class="box">
    <view class="view_slider" v-for="(item,index) in dataForm.list">
      <view class="left_slider" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd(index)">
        <view class="left_slider_clone">
          left盒子
        </view>
      </view>
      <view class="right_slider" :class="{ hide: !item.select }" @click="handleDel(index)">
        取消
      </view>
    </view>
  </view>
</template>

<script setup>
  import { reactive } from 'vue'
  const dataForm = reactive({
    list:[
      { select:false },
      { select:false },
      { select:false },
      { select:false },
    ],
    sleb:0,
    timer:null,
    index:0,
  });
  
  const touchStart = (e) => {
    // console.log(e);
    console.log(e.touches[0].clientX);
    dataForm.sleb = e.touches[0].clientX;
  };
  const touchMove = (e) => {
    // console.log(e);
    // console.log(e.touches[0].clientX);
    clearTimeout(dataForm.timer);
    dataForm.timer = setTimeout(() => {
      // 排它
      dataForm.list.forEach(item => {
        item.select = false;
      })
      const delTax = e.touches[0].clientX - dataForm.sleb;
      if(delTax < -10){
        // 向左滑动
        console.log("向左滑动",delTax);
        dataForm.list[dataForm.index].select = true;
      }else if(delTax > 10){
        // 向右滑动
        console.log("向右滑动",delTax);
        dataForm.list[dataForm.index].select = false;
      }
    },300);
  };
  // 获取索引index
  const touchEnd = (i) => {
    console.log(i);
    dataForm.index = i;
  };
  // 删除
  const handleDel = (i) => {
    console.log("删除",i);
  }
</script>

<style scoped>
      .view_slider{
      display: flex;
      width: 100%;
      height: 100px;
      background-color: pink;
      margin-bottom: 6px;
    }
    .left_slider{
      width: 100%;
      height: 100%;
      background-color:bisque;
      overflow: hidden;
    }
    .left_slider_clone{
      display: inline-block;
      width: 100% !important;
      height: 100% !important;
      /* 看情况给 */
      text-align: left;
    }
    .right_slider{
      width: 20%;
      height: 100%;
      background-color: aqua;
    }
    .hide{
      display: none;
    }
</style>

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值