methods:{
handleLetterClick(e){
this.$emit('change',e.target.innerText)
},
handleTouchStart(){
this.touchStatus = true
},
handleTouchMove(e){
if(this.touchStatus){
if(this.timer){
clearTimeout(this.timer)
}
this.timer = setTimeout(()=>{
const touchY = e.touches[0].clientY-79
const index = Math.floor((touchY - this.startY)/20)
if(index >= 0 && index<this.letters.length){
this.$emit('change',this.letters[index])
}
},30)
}
},
handleTouchEnd(){
this.touchStatus=false
}
}
手指滑动开始,touchStatus值为true。touchStatus值为true 的话,清除函数timer,然后重新赋值一个函数timer并在30m后运行代码,然后一直不断重复的清除函数timer,然后重新赋值一个函数timer并在30m后运行。