一:图片宽度自动
//wxml
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
<block wx:for="{{imgUrls}}" wx:key="image">
<swiper-item>
<image src=http://www.yiyongtong.com/archives/"{{item.image}}" model="aspectFit" style="width: {{imageWidth}}px;" bindload="imageLoad" />
</swiper-item>
</block>
</swiper>
//js
imageLoad: function () {
this.setData({
imageWidth: wx.getSystemInfoSync().windowWidth,//图片宽度
imgUrls: [
{ image: "" },
{ image: "" },
{ image: "" }],
indicatorDots: false,//是否显示圆点
autoplay: true,//自动播放
interval: 2000,//间隔时间
duration: 1000//监听滚动和点击事件
})
}
二:获取组件数据
//wxml
<dt data-index="{{idMenu}}" bindtap="tapMainMenu">{{menuItem.reportType}}</dt>
//js
tapMainMenu: function (e) {
//获取当前一级菜单标识
var index = parseInt(e.currentTarget.dataset.index);