日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

mpvue 中控制swiper滑动,禁止滑动,只允许左滑动,不允许右滑

發布時間:2023/12/10 vue 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mpvue 中控制swiper滑动,禁止滑动,只允许左滑动,不允许右滑 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

直接禁止滑動,使用:catchtouchmove參數就OK。

例子:

<swiper-item v-for="(item,index) in examList" :key="index" catchtouchmove="false">content</swiper-item>

但是我的需求是進行人員測評,已經測評過的swiper-item允許左右滑動,沒有測評過的swiper-item不允許滑動。所以我需要自定義監聽左滑、右滑,然后結合業務邏輯,直接進行控制就行。需要用到的屬性:
touchStart,touchmove.stop。大概的思路代碼如下:

<swiper class="swiper" :current="currentSwiper" :autoplay="autoplay" :interval="interval" previous-margin="12rpx" next-margin="22rpx" :circular="circular" :duration="duration" @change="swiperChange"><swiper-item v-for="(item,index) in examList" :key="index" @touchstart="touchStart" @touchmove.stop="touchMove">content</swiper-item> </swiper> data() {return {clientX1: 0, // 滑動開始位置} }, methods: {touchStart (e) {this.clientX1 = e.clientX},touchMove (e) {if (this.clientX1 === 0) return falseconst clientX2 = e.clientXlet disX = this.clientX1 - clientX2// 判斷左右滑動的閥值為15if (disX > 15) {// 左滑this.currentSwiper = this.currentSwiper + 1this.clientX1 = 0}if (disX < -15) {// 右滑this.currentSwiper = this.currentSwiper - 1this.clientX1 = 0}} }

通過這個例子,我們需要了解catchtouchmove,touchmove.stop。雖不常用,但是有用。

總結

以上是生活随笔為你收集整理的mpvue 中控制swiper滑动,禁止滑动,只允许左滑动,不允许右滑的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。