綁定bindchange事件的微信小程序swiper閃爍,抖動問題解決,(將微信小程序切換到后台一段時間,再打開微信小程序,會出現瘋狂循環輪播,造成抖動現象)


微信小程序開發文檔-組件-swiper后面追加的新聞如上圖所示;

如果在bindchange事件給swiper的current屬性對應的值{{current}}賦值,就會造成抖動現象。

1   bindchangeSwiper(event) {
2     console.log(event.detail);
3     this.setData({
4       current: event.detail.current
5     })
6   },

可是有的時候我們確實需要動態獲取當前的swiper-item索引,用來額外做一些其他操作;

為了解決這個問題,我們需要額外定義一個變量。

1     current: 0, // swiper初始對應的swiper-item
2     currentIndex: 0, // 用來記錄當前swiper對應的索引index
1   bindchangeSwiper(event) {
2     this.setData({
3       currentIndex: event.detail.current
4     })
5   },

 

這樣問題解決啦! 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM