微信小程序轮播图实现(超简单)

微信小程序轮播图实现(超简单)

微信小程序的轮播图可以用官方给的swiper组件。
下图是官方给出的swiper属性,我截取了比较常用的一些属性。
在这里插入图片描述
效果实现如下图
效果图

1. 普通开发(不采用云开发)

1.1wxml

<view class="banner">
   <swiper indicator-dots indicator-color="rgba(255,255,255,0.5)"
   indicator-active-color="#fff" circular autoplay interval="4000">
   <swiper-item><image src="/image/1.jpg"></image></swiper-item>
   <swiper-item><image src="/image/2.jpg"></image></swiper-item>
   <swiper-item><image src="/image/3.jpg"></image></swiper-item>
   </swiper>
</view>

1.2wxss


.banner{
  width: 100%;
  height: 350rpx;
}
.banner swiper{
  height: 100%;
  width: 100%;
}
.banner image{
  width: 100%;
  height: 350rpx;
}

2. 采用云开发

2.1wxml

<view class="banner">
   <swiper indicator-dots indicator-color="rgba(255,255,255,0.5)"
   indicator-active-color="#fff" circular autoplay interval="4000">
   <swiper-item wx:for="{{list}}">
     <image src="{{item.imge}}"></image>
    </swiper-item>
   </swiper>
</view>

2.2wxss

.banner{
  width: 100%;
  height: 400rpx;
}
.banner swiper{
  height: 100%;
  width: 100%;
}
.banner image{
  width: 100%;
  height: 400rpx;
}

2.3js

getTopList(){
  wx.cloud.database().collection('lunbo').get()
  .then(res => {
    console.log("数据上传成功",res)
  this.setData ({
    list:res.data 
  })
})

自己赶紧试试吧,只需件swiper组件中写入image,将image中的src中的路径换成自己图片的路径就可以了,

  • 31
    点赞
  • 93
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

code袁

你的支持是我莫大的幸运

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值