1,其实uni中有一个movable-area是可以实现的,而且实现的挺好,但怪就怪我自己实现了一下…
2、u-view更有一个SwipeAction 滑动操作 可太香了,我要换了,溜了溜了
核心两个事件(我改了人家的):
@touchmove="drawMove($event,item,index)" @touchend="drawEnd"
drawMove(e,item,index) {
// console.log(e,item,index)
console.log("滑动");
// console.log(e,v,a)
let nowTime = +new Date()
console.log(nowTime)
//节流
if(nowTime - 500 >this.lastTimer){
console.log(e)
console.log(1)
this.lastTimer = nowTime
if(this.lastMove == 0){
this.lastMove = e.changedTouches[0].clientX
}
// 如果距离上一次超出了 10像素 && 这一次的位置-上一次的位置 > 0 就是向左滑动的
if(Math.abs(e.changedTouches[0].clientX - this.lastMove) >10 && e.changedTouches[0].clientX - this.lastMove <0){
console.log('向左')
item.setDel = false
let newItme = item
this.list.splice(index,1,newItme)
console.log(this.list)
// this.$set(this.list[index])
}
// 如果距离上一次低 20像素 && 这一次的位置-上一次的位置 < 0 就是向右滑动的
if(Math.abs(e.changedTouches[0].clientX - this.lastMove) >10 && e.changedTouches[0].clientX- this.lastMove > 0){
console.log('向右')
item.setDel = true
let newItme = item
this.list.splice(index,1,newItme)
}
}
},
drawEnd(e) {
console.log("滑动结束");
this.lastMove = 0
this.lastTimer = 0
},