頁面-輪播圖-點(diǎn)擊跳轉(zhuǎn)

//wxml,
      <swiper class="swipersize" indicator-dots="true" catchtap="swiperclick"
        autoplay="true" interval="3000" circular="true" duration="1000" next-margin="0rpx">
         <block wx:for="{{testdata4}}" wx:for-index="index">
         <view wx:if="{{index>=1&&index<=3}}">
          <swiper-item>
            <image src="{{testdata4[index].picpath}}" class="slide-image" bindtap='img' data-id='{{index}}'/>
          </swiper-item>
         </view>
        </block> 
      </swiper>
//js,數(shù)據(jù)處理在onload函數(shù)里
    //判斷緩存中有無數(shù)據(jù),有就賦值,沒有就請求數(shù)據(jù),存入緩存,并賦值
    huancun = wx.getStorageSync('lunbopic')
    if(huancun){
      that.setData({
        testdata4: huancun,
      })  
    }else{
    //輪播請求
    wx.request({
      //url: app.globalData.site + '/Husbandry_Manage/WeiXinCasesServlet?type=picture&minitype=minilb',
      url: app.globalData.site + '/Husbandry_Manage/WeiXinCasesServlet',
      data: {
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function (res) {
        //console.log(res.data[2].picture)
        //存入緩存
        wx.setStorageSync('lunbopic', res.data[2].picture)
        //設(shè)置數(shù)據(jù)
        that.setData({
          testdata4: res.data[2].picture,
        })
      }
    })
    }

//輪播點(diǎn)擊事件,事件處理函數(shù)
  swiperclick: function (e) {
   var picid=e.target.dataset.id;
   console.log(picid)
   switch (picid) {
     case 1:
       wx.navigateTo({
         url: '../../pages/joinus/joinus',
       })
       break;
     case 2:
       wx.navigateTo({
         url: '../../pages/industry/industry',
       })
       break;
     case 3:
       wx.navigateTo({
         url: '../../pages/mall/mall',
       })
       break;
   }
  },

數(shù)據(jù)格式:


image.png
.swipersize{
  width:100%;
  height: 380rpx;
}
.slide-image{
    width: 100%;
    height: 380rpx;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容