vue-uniapp-滑动处理

代码如下

<view
            v-for="(item,index1) in dataList"
            :key="index1"
            :class=" (item.pxxh %2 ==0) ? itemContent1:itemContent"
            @touchmove="handletouchmove"
            @touchstart="handletouchstart"
            @touchend="deleteShow(index1)"
        >


data () {
        return {
            rowMoveCtrl: {
                flag: 0,
                text: '没有滑动',
                lastX: 0,
                lastY: 0
            },

        handletouchstart (event){
            this.rowMoveCtrl.lastX = event.touches[0].pageX
            this.rowMoveCtrl.lastY = event.touches[0].pageY
        },
        handletouchmove (event){
            if(this.rowMoveCtrl.flag !== 0){
                return
            }
            let curX = event.touches[0].pageX
            let curY = event.touches[0].pageY
            let difX = curX - this.rowMoveCtrl.lastX
            let difY = curY - this.rowMoveCtrl.lastY
            let text = ''
            // 左右方向滑动判断
            if(Math.abs(difX) > Math.abs(difY)){
                if(difX < 0){
                    text = '向左滑动'
                    this.rowMoveCtrl.flag = 1
                } else if(difX > 0){
                    text = '向右滑动'
                    this.rowMoveCtrl.flag = 2
                }
            } else {
                // 上下方向滑动判断
                if(ty < 0){
                    text = '向上滑动'
                    this.rowMoveCtrl.flag = 3
                }else if(ty > 0){
                    text = '向下滑动'
                    this.rowMoveCtrl.flag = 4
                }
            }
            this.rowMoveCtrl.lastX = curX
            this.rowMoveCtrl.lastY = curY
            this.rowMoveCtrl.text = text
        },
        deleteShow (curIndex){
            if(this.rowMoveCtrl.flag === 0){
                return
            } else if(this.rowMoveCtrl.flag === 2){
                // 向右滑动
                this.bdelete[curIndex].visible = true
            }
            this.rowMoveCtrl.flag = 0
            this.rowMoveCtrl.text = '没有滑动'
            
        },

上一篇:用AutoHotkey调用VBA一键给word文档添加多级列表。


下一篇:Paddle和PaddleDetection的个人经历