//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,
})
}
})
}
//輪播點擊事件,事件處理函數(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ù)格式:
.swipersize{
width:100%;
height: 380rpx;
}
.slide-image{
width: 100%;
height: 380rpx;
}