瀟瀟雨雨
2019-03-22 22:19:16
vue中使用better-scroll @click事件執(zhí)行兩次,請問怎么解決
3 回答

湖上湖
TA貢獻2003條經(jīng)驗 獲得超2個贊
同出過該問題,備注一下:
一開始以為跟項目中的fastclick沖突,后確認非該原因導致。
官網(wǎng)Demo也沒有類似問題,最后暫時改為@touchstart+@touchend.stop.prevent模擬@click。
示例代碼:
<template>
<button @touchstart="start($event)" @touchend.stop.prevent="stop($event)">Test</button>
</template>
<script>
export default {
methods: {
start ($event) {
this.startY = $event.touches[0].pageY
},
stop ($event) {
const moving = Math.abs($event.changedTouches[0].pageY - this.startY)
if (moving > 20) return
this.startY = 0
console.log('click')
}
}
}
</script>
添加回答
舉報
0/150
提交
取消