[前端] vue长按事件touch示例详解

2155 0
黑夜隐士 2022-10-21 15:42:07 | 显示全部楼层 |阅读模式
目录

    1.touch事件2.长按弹出删除按钮,点击删除


1.touch事件

以下是四种touch事件
touchstart:     //手指放到屏幕上时触发
touchmove:      //手指在屏幕上滑动式触发
touchend:    //手指离开屏幕时触发
touchcancel:     //系统取消touch事件的时候触发,这个好像比较少用

2.长按弹出删除按钮,点击删除
  1. <div v-for="item in list" @touchstart.native="showDeleteButton(item.id)" @touchend.native="clearLoop(item.id)">
  2.         内容...
  3. </div>
复制代码
  1. showDeleteButton(e) {
  2.         clearTimeout(this.Loop); //再次清空定时器,防止重复注册定时器
  3.         this.Loop = setTimeout(function() {
  4.                 this.$dialog.confirm({   //这是个弹出框,用的ydui
  5.                         title: '温馨提示',
  6.                         mes: '是否删除此条消息',
  7.                         opts: () => {
  8.                                 this.$dialog.loading.open('删除中...');
  9.                                 this.$http.post(this.$store.state.ip + '...', {
  10.                                         id: e
  11.                                 }, {
  12.                                     headers: {},
  13.                                 }).then((response) => {
  14.                                         this.$dialog.loading.close();
  15.                                                 this.$dialog.toast({
  16.                                                         mes: response.body.info,
  17.                                                         timeout: 1000
  18.                                                 });
  19.                                                 var data = this.rulist
  20.                                                 console.log(data)
  21.                                                 for(var i in data) {
  22.                                                         if(data[i].id == e) {
  23.                                                                 data.splice(i, 1)
  24.                                                         }
  25.                                                 }
  26.                                                 console.log(data)
  27.                                                 this.rulist=data
  28.                                                 }).catch(function(response) {
  29.                                                 });
  30.                                         }
  31.                 });
  32.         }.bind(this), 1000);
  33. },
  34. clearLoop(e) {
  35.         clearTimeout(this.Loop);
  36. },
复制代码
补充:下面看下Vue长按触摸事件
开始触摸:
  1. @touchstart="touchClose()"
复制代码
触摸结束:
  1. @touchend="touchOpen()"
复制代码
使用示例:




到此这篇关于vue长按事件touch的文章就介绍到这了,更多相关vue长按事件touch内容请搜索中国红客联盟以前的文章或继续浏览下面的相关文章希望大家以后多多支持中国红客联盟!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行