uniapp Swiper 禁用滑动:详细步骤及代码示例
<template>
<swiper :options="swiperOptions" @change="swiperChange"></swiper>
</template>
<script>
export default {
data() {
return {
swiperOptions: {
// Swiper配置
},
isSwiperLocked: false
}
},
methods: {
swiperChange() {
if (!this.isSwiperLocked) {
this.$refs.swiper.lockSwipes();
this.isSwiperLocked = true;
}
}
}
}
</script>
<p>在上面的代码中,我们在<code>swiperOptions</code>中配置了Swiper,然后在<code>swiperChange</code>方法中使用<code>this.$refs.swiper.lockSwipes()</code>方法将Swiper锁定。为了避免重复调用<code>lockSwipes()</code>方法,我们使用了一个<code>isSwiperLocked</code>变量来记录Swiper的状态。</p>
原文地址: https://www.cveoy.top/t/topic/m5pD 著作权归作者所有。请勿转载和采集!