uniapp swiper 禁止左滑
要禁止uniapp中swiper组件的左滑功能,可以通过以下步骤实现:
- 给swiper组件绑定touchmove事件,并阻止默认事件:
<swiper @touchmove.stop></swiper>
- 在touchmove事件中获取手指滑动的方向,如果是向左滑动则禁止滑动:
<swiper @touchmove="onTouchMove"></swiper>
// 在methods中添加onTouchMove方法
onTouchMove(event) {
// 获取手指滑动的方向
const { deltaX, deltaY } = event.touches[0]
if (deltaX < 0 && Math.abs(deltaX) > Math.abs(deltaY)) {
// 如果是向左滑动,则禁止滑动
event.preventDefault()
}
}
通过以上步骤,就可以禁止swiper组件的左滑功能了。
原文地址: https://www.cveoy.top/t/topic/bA9a 著作权归作者所有。请勿转载和采集!