綁定bindchange事件的微信小程序swiper閃爍,抖動問題解決,(將微信小程序切換到後臺一段時間,再打開微信小程序,會出現瘋狂循環輪播,造成抖動現象)
阿新 • • 發佈:2019-02-18
com 程序開發 記錄 his 其他 我們 tin 開發文檔 出現
微信小程序開發文檔-組件-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 },
這樣問題解決啦!
綁定bindchange事件的微信小程序swiper閃爍,抖動問題解決,(將微信小程序切換到後臺一段時間,再打開微信小程序,會出現瘋狂循環輪播,造成抖動現象)