支付宝小程序轮播组件

轮播组件传值有个奇怪现象,就是必须为propArray

axml部分

<view class="swiper-container">
  <swiper indicator-dots="{{indicatorDots}}" interval="{{interval}}" duration="{{duration}}" circular="{{duration}}"
   onChange="swiperChange" class="swiper" autoplay="{{autoplay}}">
    <block a:for="{{propArray}}" a:key="unique">
      <swiper-item>
        <image src="{{item.imgs}}" data-link="{{item.link}}" class="img" onTap="swipclick"  />
      </swiper-item>
    </block>
  </swiper>
  <view class="dots">
    <block a:for="{{propArray}}" a:key="unique">
      <view class="dot{{index == swiperCurrent ? ' active' : ''}}" data-id="{{item.id}}" onTap="chuangEvent"></view>
    </block>
  </view>
</view>

acs部分

swiper {
    height:485rpx;
}
swiper-item image {
    width: 100%;
    height: 100%;
}
.swiper-container{
  position: relative;
}
.swiper-container .swiper{
  height:485rpx;
}
.swiper-container .swiper .img{
  width: 100%;
}
/* 轮播小点 */
.dots{ 
  position: absolute; 
  left: 0; 
  right: 0; 
  bottom: 20rpx; 
  display: flex; 
  justify-content: center; 
} 
.dots .dot{ 
  margin: 0 8rpx; 
  width: 10rpx; 
  height: 6rpx; 
  background: #ddd; 
  border-radius: 8rpx; 
  transition: all .6s; 
} 
.dots .dot.active{ 
  width: 22rpx;
  background: #1888f0; 
}

js部分

Component({
  mixins: [],
  props: {
    propArray: {
      type: Array,
      value: ''
    },
    links:{
      type: Array,
      value: ''
    }
  },

  data: {
    imgsbox: [],
    swiperCurrent: 0,
    autoplay: true,
    interval: 3000,
    duration: 800,
    circular: true,
    // 将轮播图组件自带的小点隐藏
    indicatorDots: false,
  },
  didMount() { },
  didUpdate() {
    this.setData({
      imgsbox: this.props.imgUrls
    })
  },
  didUnmount() { },
  /**
     * 组件的方法列表
     */
  methods: {
  //轮播图的切换事件
    swiperChange: function(e) {
      this.setData({
        swiperCurrent: e.detail.current
      })
    },
    //点击指示点切换
    chuangEvent: function(e) {
      this.setData({
        swiperCurrent: e.currentTarget.id
      })
    },
    //点击图片触发事件
    swipclick: function(e) {
      var link = e.target.dataset.link;
      if (link == "" || link==null){
        return false;
      }else{
        my.navigateTo({ url: link })
      }
    }
  }
});

 

转载于:https://www.cnblogs.com/fms-3/p/10180356.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值