uniapp右侧滑操作

 记录uniapp使用uni-swipe-action后打包app报错问题.自定义一个侧滑操作
一.html部分

<view class="productList" style="margin-bottom: 20rpx" v-for="(item, index) in pageData.productList" :key="item.id">
        <view
          :style="{ left: pageData.productList[index].boxLeft }"
          class="section"
          @touchstart="drawStart"
          @touchmove="drawMove($event, index)"
          @touchend="drawEnd($event, index)"
        >
          <view class="productItem" @click.stop="restore(index)"> 内容 </view>
          <view class="function">
            <view class="operation">
              <view class="edit-operation operation_box"> 操作部分 </view>
            </view>
          </view>
        </view>
      </view>

二.JS部分

const pageData = reactive({
    productList: []
})

//侧滑操作
const clientX = ref(0)

// 开始触摸
const drawStart = e => {
  // 获取开始触摸时的位置
  clientX.value = e.changedTouches[0].clientX
}
// 触摸过程
const drawMove = e => {
  //获取触摸过程中的结束位置
}
// 结束触摸
const drawEnd = (e, index) => {
  var endX = e.changedTouches[0].clientX
  let diff = endX - clientX.value
  // 防止误触 -- 给一个误差区间,防止用户误触.值(100)根据自己需求定义
  if (Math.abs(diff) > 100) {
    if (diff < 0) {
      pageData.productList[index].boxLeft = '-200rpx'
    } else {
      pageData.productList[index].boxLeft = '0'
    }
  }
}
// 点击恢复原来的位置
const restore = index => {
  pageData.productList[index].boxLeft = '0'
}

三.CSS部分

.section {
  min-height: 100%;
  width: 100%;
  margin-bottom: 16rpx;
  position: relative;
  transition: all 0.5s linear;
  left: 0;

  .function {
    height: 100%;
    border-radius: 8rpx;
    position: absolute;
    right: -140rpx;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值