uniapp swiper禁止滑动
禁用 Swiper 滑动的方法
在 UniApp 中,可以通过设置 disable-touch 属性或动态控制 touchable 参数来禁止 Swiper 组件的滑动。
方法一:通过 disable-touch 属性
在 Swiper 标签中添加 disable-touch 属性,值为 true 时禁止滑动:
<swiper :disable-touch="true">
<swiper-item>内容1</swiper-item>
<swiper-item>内容2</swiper-item>
</swiper>
方法二:动态控制 touchable 参数
通过数据绑定动态控制滑动行为:
<swiper :touchable="isTouchable">
<swiper-item>内容1</swiper-item>
<swiper-item>内容2</swiper-item>
</swiper>
在脚本中定义 isTouchable 变量:
export default {
data() {
return {
isTouchable: false // false表示禁止滑动
}
}
}
注意事项
- 部分平台可能对
disable-touch或touchable的支持存在差异,需测试目标平台的兼容性。 - 禁用滑动后,Swiper 的指示点(dots)和自动播放等功能仍可正常使用。







