Title
 //长按的几个事件

 @touchstart.native="gtouchstart(file)"

@touchmove.native="gtouchmove()"

@touchend.native="showDeleteButton(file)"
复制代码
//手机上操作才可以看见下载

download(href, name) {
       debugger

      let eleLink = document.createElement("a");

      eleLink.download = name;

      eleLink.href = href;

      eleLink.click();

      eleLink.remove();

    },

    //长按事件(起始)

    gtouchstart(item) {
      var self = this;

      this.timeOutEvent = setTimeout(function() {
        self.longPress(item);

      }, 500); //这里设置定时器,定义长按500毫秒触发长按事件

      return false;

    },

    //手释放,如果在500毫秒内就释放,则取消长按事件,此时可以执行onclick应该执行的事件

    showDeleteButton(item) {
      clearTimeout(this.timeOutEvent); //清除定时器

      if (this.timeOutEvent != 0) {
        //这里写要执行的内容(如onclick事件)

        console.log("点击但未长按");

      }

      return false;

    },

    //如果手指有移动,则取消所有事件,此时说明用户只是要移动而不是长按

    gtouchmove() {
      clearTimeout(this.timeOutEvent); //清除定时器

      this.timeOutEvent = 0;

    },

    //真正长按后应该执行的内容

    longPress(val) {
      console.log(val);

      let _this = this;

      this.timeOutEvent = 0;

      _this.download(this.downloadFileServer + val.fSrc, "imgname");

//this.downloadFileServer + val.fSrc:路径

      // debugger;

      console.log("长按");

    },
复制代码

 

posted on   月见白  阅读(891)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界



点击右上角即可分享
微信分享提示