作者:gou-tian
来自:github
幻灯片
运用微信小顺序原生组件swiper完成。
<swiper
indicator-dots="{{indicatorDots}}"
autoplay="{{autoplay}}"
interval="{{interval}}"
duration="{{duration}}">
<block wx:for="{{imgUrls}}" wx:key="index">
<swiper-item>
<image src="{{item}}" class="slide-image"
mode="scaleToFill"/>
</swiper-item>
</block>
</swiper>
配合在逻辑页面设置数据完成幻灯片
Page({
data: {
imgUrls: [],
indicatorDots: true,
autoplay: true,
interval: 2000,
duration: 1000,
},
onLoad: function(){
util.ajax({
url: 'https://api.zg5v.com/index.php/index/show/banner',
data: {
uid: 194
},
cb: function(res) {
setSilde.call(self, res.data.data);
}
});
}
})
tab导航切换
因为微信小顺序不能直接操纵DOM,所以这里设置一个data-id值。(data-id=”{{index}}”
)用来模仿DOM操纵,来完成导航内容的切换
<view class="nav-warp">
<view class="tab">
<block wx:for="{{navItem}}" wx:key="index">
<text bindtap="navToggle"
data-id="{{index}}"
class="tab-txt
{{showItem == index ? 'active' : '' }}">
{{item}}
</text>
</block>
</view>
</view>
用于模仿DOM操纵
Page({
data: {
showItem: 0
},
navToggle: function(e){
this.setData({
showItem: e.target.dataset.id
});
util.dataList.call(this, {
url: 'https://api.zg5v.com/index.php/index/show/qtshow',
data: {
uid: 148,
fenid: e.target.dataset.id - 1,
num: 0
},
cb: util.petAge
});
}
});
转自:转载地点