vue touch事件,长按1秒显示删除按钮。

vue touch事件,长按1秒显示删除按钮。我是这样写的,但是实现不了,请问应该怎么修改呢?

<div class="card" v-for="(floor,index) in floors_list" @touchstart="showDeleteButton" @touchend="clearLoop">
    <div class="delete-button" :class="{'delete-button-show': isDeleting}" @click="clickDelFloor(index)">x</div>
</div>

showDeleteButton() {
    clearInterval(this.Loop);//再次清空定时器,防止重复注册定时器
    this.Loop=setTimeout(function(){
        this.isDeleting = true;
    },1000);
},
clearLoop() {
    clearInterval(this.Loop);
},
阅读 17.9k
3 个回答

应该是this的指向错了

var This = this;
this.Loop = setTimeout(function(){
This.isDeleting = true;
},1000);

可以使用箭头函数
setTimeout(() => {}, timeout);

 this.Loop=setTimeout(function(){
        this.isDeleting = true;
    }.bind(this),1000);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题