vue長按事件touch
阿新 • • 發佈:2019-02-20
1.touch事件
以下是四種touch事件
touchstart: //手指放到螢幕上時觸發
touchmove: //手指在螢幕上滑動式觸發
touchend: //手指離開螢幕時觸發
touchcancel: //系統取消touch事件的時候觸發,這個好像比較少用
2.長按彈出刪除按鈕,點選刪除
<div v-for="item in list" @touchstart.native="showDeleteButton(item.id)" @touchend.native="clearLoop(item.id)"> 內容... </div>
showDeleteButton(e) { clearTimeout(this.Loop); //再次清空定時器,防止重複註冊定時器 this.Loop = setTimeout(function() { this.$dialog.confirm({ //這是個彈出框,用的ydui title: '溫馨提示', mes: '是否刪除此條訊息', opts: () => { this.$dialog.loading.open('刪除中...'); this.$http.post(this.$store.state.ip + '...', { id: e }, { headers: {}, }).then((response) => { this.$dialog.loading.close(); this.$dialog.toast({ mes: response.body.info, timeout: 1000 }); var data = this.rulist console.log(data) for(var i in data) { if(data[i].id == e) { data.splice(i, 1) } } console.log(data) this.rulist=data }).catch(function(response) { }); } }); }.bind(this), 1000); }, clearLoop(e) { clearTimeout(this.Loop); },