vue-移动端购物车滑动事件-左滑删除-mintUI

购物车左滑事件

goods.startx = 0;//滑动
goods.endx = 0;//结束
goods.isshow = false;//显示隐藏 

标签中添加滑动事件 

<div :class="{list:true,activeleft:item.isshow}" v-for="(item,idx) of goods" :key="idx" 
	@touchstart="start($event,idx)"
	@touchmove="move($event,idx)"
	@touchend="end(idx)"
>

事件处理函数

// 购物车左滑事件 ---重要
start: function(e,idx) {
  // console.log(e.targetTouches[0].clientX,111)
  this.goods[idx].startx = e.targetTouches[0].clientX;
  this.goods[idx].endx = 0;
},
move(e,idx) {
  // console.log(e.targetTouches[0].clientX,222)
  this.goods[idx].endx = e.targetTouches[0].clientX;
},
end(idx) {
  //结束的坐标点大于开始的坐标点,认为用户已经从左往右滑动了屏幕
  if(this.goods[idx].endx == 0)return;
  if(this.goods[idx].startx > this.goods[idx].endx){
	this.goods[idx].isshow = true;
  }else{
	this.goods[idx].isshow = false;
  }
  this.$forceUpdate();//强制刷新  重要
  // console.log(this.goods[idx].isshow,3333333)
}

 

posted @   JackieDYH  阅读(48)  评论(0编辑  收藏  举报  
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示