微信小程序-swiper更换list

444 阅读1分钟

根据不同的条件,展示不同的轮播图时,在切换list时会报错

TypeError: Cannot read property '?' of undefined at HTMLElement._attached.wx.getPlatform._touchstartHandlerForDevtools

解决:添加current属性,在更改列表之前,需重置current

<swiper indicator-active-color="{{indicatorActiveColor}}" indicator-dots autoplay interval="{{interval}}" duration="{{duration}}" circular current="{{current}}">  <repeat for="{{bannerList}}">    <swiper-item>      <image src="{{item.image}}" />    </swiper-item>  </repeat></swiper>

data = {
  current: 0
}

changeList() {
  this.current = 0
  this.bannerList = [{
    image: 'https:xxxxx'
  }, {
    image: 'https:xxxxx'
  }]
}