使用Mint-ui中的cell-swipe组件如何解决滑动删除和路由跳转同时触发问题

出现问题

mint-ui在使用cell-swipe时滑动删除和路由跳转会同时触发。这肯定不是我们想要的结果。

如何解决

不使用组件本身的to进行跳转,而是通过点击事件配合移动端touch事件进行跳转。

直接上代码

HTML

	<div v-for="(item, index) in testList" key:="index" @click="handleRouter(item)">
      <mt-cell-swipe 
        v-if="item.id == 1"
        class="ct-list-hw"
        @touchstart.native="sideslip(item, '1')"
        @touchmove.native="sideslip(item, '2')"
        @touchend.native="sideslip(item,'3')"
        :right="[{
          content: '删除',
          style: { background: 'red', color: '#fff', padding: '20px 10px 0px 10px' },
          handler: () => deleteBtn(item.XXX, $event)
        }]"
        >
        <div>list样式</div>
      </mt-cell-swipe>
      <div v-else>如果需求要求右侧滑动和不滑动交替进行,可使用此HTML,否则直接使用mt-cell-swipe</div>
     </div>

js

	//接口获取到的列表数据testList
	that.testList.forEach((item,index)=>{
	   this.$set(that.testList,index,Object.assign({},{isFlag:true,timer:null},item))
	})
//侧滑事件
    sideslip(item,flag){
      if(flag == 1) if(item.timer) clearTimeout(item.timer);
      if(flag == 2) {item.isFlag = false;}
      if(flag == 3) item.timer = setTimeout(()=>{item.isFlag = true},2)
    },
    //防止侧滑是误触上拉加载
    pullScroll(type){
      //若存在项的isFlag为false(意味着触发cell-swipe),则返回;
      let isFlag = this.dataList.some(item=>!item.isFlag);
      if(isFlag) return;
      this.getList(type); //获取列表数据
    },

css

	//class="ct-list-hw"在<mt-cell-swipe>样式</mt-cell-swipe>中使用样式,需要改变默认样式,自己找吧。
	
	//修改mt-cell-swipe默认样式
	.ct-list-hw .mint-cell-title {
	   flex: none;
	}
	.ct-list-hw .mint-cell-value {
	   flex: 100%
	}

注意:为自定义组件加上原生事件记得使用 .native 修饰符

写在最后
如此详细,一方面为了自己做个笔记,毕竟mint-ui官网实在太简洁了,一方面为了在电脑面前困恼到头秃的你。让我们一起努力赚钱吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值